spring在java项目中起着至关重要的作用,尤其是在java web项目中,但是往往复杂的项目中配置也就越复杂,jar包版本的混乱,配置文件的复杂等等,会让人看的心烦。spring boot的兴起让这一切都有了改变,减少甚至去除了xml配置,实现了配置统一化。 Spring Boot的主要优点:
为所有Spring开发者更快的入门开箱即用,提供各种默认配置来简化项目配置内嵌式容器简化Web项目没有冗余代码生成和XML配置的要求创建spring boot项目 - 创建maven项目,配置pom.xml
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.3.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> 创建启动类 @SpringBootApplication public class SpringBootStartApplication { public static void main(String[] args) { SpringApplication.run(SpringBootStartApplication.class, args); } } 创建controller @RestController public class IndexWeb { @RequestMapping("/") public String index() { return "Hello"; } } 启动主程序,访问http://localhost:8080