Springboot框架搭建
Springboot框架搭建
Eclipse+Maven
1.新建一个maven-webapp项目,并删除webapp文件夹
2.添加项目依赖
(1)将项目添加为Springboot的子项目,并添加依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.6.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
3.在包目录下新建一个启动类
3.新建一个文件为application.properties
写上项目配置
server.port=8081//更改端口号为8081
4.新建main方法编写启动方法
package com.mm;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MainApp{
public static void main(String[] args) {
SpringApplication.run(MainApp.class, args);
}
}
5.新建controller组件
package com.mm.test.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class TestController {
@RequestMapping("/")
public String test() {
return "hello";
}
}
6.启动MainApp,在浏览器中输入localhost:8081就可以看见效果
7.项目代码
还没有评论,来说两句吧...