开始
延迟初始化
bean不会一开始就初始化,启动快,但是相应的bean配置错误不会在一开始显现出来
1 2 3
| spring: main: lazy-initialization: true
|
元数据支持
引入configuration-processor
依赖,在yaml中配置也会有相应提示
1 2 3 4 5
| <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency>
|

会生成metadata.json
配置属性
Javabean属性绑定和Constructor绑定

yaml
1 2 3 4 5 6 7
| acme: enabled: false remote-address: 192.168.45.113 security: username: root password: root roles: [11,22,33]
|
松散绑定
了解一下

JSR-303属性校验

如果存在内部类,在内部类加上@Valid注解才会生效
@ConfigurationProperties vs. @Value
特征 |
@ConfigurationProperties |
@Value |
松散绑定 |
Yes |
Limited (see note below)有限支持 |
元数据支持 |
Yes |
No |
SpEL 表达式 |
No |
Yes |
复杂类型绑定 |
Yes |
No |
JSR-303属性校验 |
Yes |
No |
Async
1 2 3 4 5 6 7 8 9 10 11 12 13
| @Service public class AsyncService {
@Async public void hello(){ try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("数据处理完成!"); } }
|
1 2 3 4 5 6 7 8 9 10 11 12 13
| @Controller public class AsyncController {
@Autowired private AsyncService asyncService;
@ResponseBody @GetMapping("hello") public String hello() { asyncService.hello(); return "OK"; } }
|
1 2 3 4 5 6 7 8 9
| @EnableAsync @SpringBootApplication public class SpringbootAsyncMailScheduledApplication {
public static void main(String[] args) { SpringApplication.run(SpringbootAsyncMailScheduledApplication.class, args); }
}
|
Schedule
1 2 3 4 5 6 7 8 9
| @Service public class ScheduledService {
@Scheduled(cron = "0/5 * * * * *") public void printDate(){ System.out.println(new Date()); } }
|
1 2 3 4 5 6 7 8 9
| @EnableScheduling @SpringBootApplication public class SpringbootAsyncMailScheduledApplication {
public static void main(String[] args) { SpringApplication.run(SpringbootAsyncMailScheduledApplication.class, args); }
}
|

Mail