1,新建一个maven 工程。
2, 在pom.xml中加入依赖关系:
1) 加入parent的关系,让它程序自动下载到所有spring boot要用的主要jar文件。
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version>
</parent>
2)加入web相关的开发包
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
3)简单的代码:
package com;
@RestController
@SpringBootApplication
public class App {
@RequestMapping("/")
public String hello(){
return "Hello world!";
}
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
其中@SpringBootApplication申明让spring boot自动给程序进行必要的配置,等价于以默认属性使用@Configuration,@EnableAutoConfiguration和@ComponentScan
@RestController返回json字符串的数据,直接可以编写RESTFul的接口;