spring boot致力于,帮助开发者快速构建spring应用。省略在繁琐的文件配置。html
使用spring boot很容易建立相对独立,适用于生产环境的spring应用。前端
建立相对独立的spring 应用。java
嵌入tomcat,jetty,等应用服务器。而不须要生成war包。再部署到服务器。web
提供相对固定的基础配置已经配置模板,从而简化你的maven配置。spring
方便的spring自动化配置。tomcat
提供准生成环境的功能,如健康检测。服务器
使用maven,或者gradle能够很是方便的建立spring-boot入门应用。mvc
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.2.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies>
hello/SampleController.javaapp
package hello; import org.springframework.boot.*; import org.springframework.boot.autoconfigure.*; import org.springframework.stereotype.*; import org.springframework.web.bind.annotation.*; @Controller @EnableAutoConfiguration public class SampleController { @RequestMapping("/") @ResponseBody String home() { return "Hello World!"; } public static void main(String[] args) throws Exception { SpringApplication.run(SampleController.class, args); } }
以上代码当中,@Controller、 @RequestMapping、@ResponseBody都是spring mvc中常见的注解。其中Controller注解用于标记,该类是一个controller,@ResponseBody用于标记该方法返回值直接做为处理结果返回给前端,而不须要去寻找试图。这两个注解可使用@RestController代替。
@EnableAutoConfiguration这个注解告诉spring根据classpath引入的包,即根据依赖关系来进行自动配置。因为该工程是spring-boot-stater-web工程,默认添加了一些如tomcat,spring-web包等。所以spring会尝试以spring-web工程来配置工程。maven