![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Spring
文章平均质量分 68
Nicholas___
这个作者很懒,什么都没留下…
展开
-
BeanPostProcessor的简单使用
日常使用到 BeanPostProcessor 的场景不多,因此不是特别熟悉,查阅了一些资料,写了个Demo,记录下来,遇到问题希望能提供一些解决的思路。简介接口定义如下:public interface BeanPostProcessor { @Nullable default Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { return bean; }原创 2021-03-30 14:21:17 · 720 阅读 · 2 评论 -
CommandLineRunner和ApplicationRunner
用途测试Spring Boot应用程序时,有的人习惯写测试用例,有的人习惯写Controller,手动去调用进行测试。有时候我会使用 CommandLineRunner 或 ApplicationRunner 进行测试。测试的方法很简单,直接让带有 @SpringBootApplication 的类实现 CommandLineRunner 并实现它的方法,运行项目即可。CommandLineRunner 示例如下:@SpringBootApplicationpublic class DemoAppl原创 2021-03-29 18:11:59 · 283 阅读 · 0 评论 -
Spring Init method 和 destroy method 的几种使用方式
1、@Bean注解方式public class TestBean { public TestBean() { System.out.println("constructor"); } /** * 初始化的方法名称不一定要使用init, * 使用init主要是为了使类结构更清晰,并且不会让人误以为此方法是一个普通方法 */ public void init() { System.out.println("init"); } /**原创 2021-03-29 14:38:56 · 848 阅读 · 3 评论