pom.xml文件修改
- 引入spring-boot支持
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>```
* 新增属性
<java.version>1.8</java.version>
* 添加依赖关系
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
springboot官方推荐我们使用spring-boot-starter-parent,spring-boot-starter-parent包含了以下信息:
* 使用java6编译级别
* 使用utf-8编码
* 实现了通用的测试框架 (JUnit, Hamcrest, Mockito).
* 智能资源过滤
* 智能的插件配置(exec plugin, surefire, Git commit ID, shade).
---
##S1.java(SpringMVC中的Controller)
package sbsc.s1.action;
import java.util.HashMap;
import java.util.Map;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class S1 {
@RequestMapping(value = "/demo", method = RequestMethod.GET)
public Map<String, Object> demo()
{
Map<String, Object> ret = new HashMap<>();
ret.put("ret", "hello world");
return ret;
}
}
---
##App.java(启动程序)
package sbsc.s1;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
- Hello world!
*/
@SpringBootApplication
public class App
{
public static void main(String[] args)
{
SpringApplication.run(App.class,args);
}
}
---
启动后访问http://127.0.0.1/demo
跟spring比较,开发web项目简单了很多。