Spring

[TOC]

Spring4.3.7特征

注解

  • @RestController@Controller类似,告知sprint这是个类是用来处理web请求的,不同的是,@RestController告诉spring将结果直接渲染到调用端并显示,功能相当于@Controller@ResponseBody结合

  • @EnableAutoConfiguration

  • SpringBootApplication 等于 @Configuration,@EnableAutoConfiguration@ComponentScan三个注解的结合

注意事项

  • 在webapp中,通常我们会把静态文件放在/webapp目录下, 但是这个目录只是在我们war包的时候有效。 使用spring-boot,将运行程序打为jar包的时候,常见的是将静态文件放在/src/main/resources/static

spring 开发创建非web应用

  1. 需要将springBootApplication设置为非web环境

     springBootApplication.setWebEnvironment(false)

    或者设置applicationContextClass属性

  2. 你执行的逻辑层实现CommandLineRunner接口,如果有多个逻辑层的类,你可以通过order注解来指定执行的顺序

  3. ApplicationRunnerCommandLineRunnerSpringApplication启动之前执行

@Value中 @与#的区别

Last updated

Was this helpful?