![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
springboot
java_小灰机
这个作者很懒,什么都没留下…
展开
-
springboot中类数据预加载之CommandLineRunner
在使用SpringBoot构建项目时,我们通常有一些预先数据的加载。那么SpringBoot提供了一个简单的方式来实现–CommandLineRunner。 CommandLineRunner是一个接口,我们需要时,只需实现该接口就行。如果存在多个加载的数据,我们也可以使用@Order注解来排序。 案例: 分别定义了一个数据加载类 MyClass ,排序为2 @Component @Or...转载 2019-03-24 22:00:57 · 393 阅读 · 0 评论 -
springboot中初始化操作之@PostConstruct
1.@PostConstruct说明 被@PostConstruct修饰的方法会在服务器加载Servlet的时候运行,并且只会被服务器调用一次,类似于Serclet的inti()方法。被@PostConstruct修饰的方法会在构造函数之后,init()方法之前运行。 如果想在生成对象时完成某些初始化操作,而偏偏这些初始化操作又依赖于依赖注入,那么久无法在构造函数中实现。为此,可以使...原创 2019-03-24 22:04:21 · 2207 阅读 · 0 评论