依赖配置pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--热部署-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
</dependencies>
引导类
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class,args);
}
}
controller类
@RestController
public class HelloWorldController {
@RequestMapping("/info")
public String info(){
return "HelloWorld";
}
}
修改默认配置
在src/main/resources下创建application.properties
server.port=8088 //内置
url=http://www.itheima.com //自定义属性
读取自定义属性
@Autowired
private Environment environment;
@RequestMapping("/info")
public String info(){
return "HelloWorld~"+environment.getProperty("url");
}