springboot学习
*springboot之hello world*
- 开发环境
开发环境JDK 1.7
开发工具(Eclipse)
项目管理工具( Maven )
- 创建Maven Project (spring-boot-hello)
- pom.xml文件
<!--
spring boot 父节点依赖,引入这个之后相关的引入就不需要添加version配置,
spring boot会自动选择最合适的版本进行添加。
-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- 指定一下jdk的版本 ,这里我们使用jdk 1.7 ,默认是1.6 -->
<java.version>1.7</java.version>
</properties>
<dependencies>
<!--
添加spring-boot-starter-web依赖
MVC,AOP的依赖
-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
- 新建启动类(Application – Main方法)
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
- 新建一个Controller类
/**
* 之前这里用的Controller
*
* @Controller
* @ResponseBody
* @Target(value={TYPE})
* @Retention(value=RUNTIME)
* @Documented
*/
@RestController
public class HelloController {
/**
* 通过@RequestMapping注解,建立请求映射
* http://localhost:8080/hello
*/
@RequestMapping("/hello")
public String hello() {
return "C U C";
}
}