单独构建Springboot框架:
1.创建maven project后在pom.xml引入spring-boot-starter-web定义
<dependencies>
//引入web包 等于引入了SpringMVC/IOC的相关jar包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
</dependencies>
2.在src/main/resources添加application.properties
server.port=8888 //Boot内置tomcat端口号
server.servlet.contextPaht=/boot //设置url访问路径项目名 boot2版本 (1版本 server.contextPath=/boot)
3.编写MyBootApplication启动类
@SpringBootApplication
public class MyBootApplication {
public static void main(String[] args) {
//启动Boot程序
SpringApplication.run(MyBootApplication.class, args);
}
}
4.编写HelloController,添加注解
@RestController
public class HelloController {
@RequestMapping("/hello")
public String hello(){
return "Hello SpringBoot";
}
}
5.启动MyBootApplication测试
http://localhost:8888/boot/hello
其他功能
-
热启动
修改Java代码后,自动redeploy
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <version>2.0.1.RELEASE</version> </dependency>