项目应用之-如何在ioc容器初始化以后自动触发某个方法完成某些业务逻辑或者配置...

本人的解决方案如下:

实现InitializingBean接口并实现afterPropertiesSet( ) 方法,该方法会在ioc容器初始化时被执行

@Component
public class InitialDemo implements InitializingBean {
    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("ioc容器初始化");
//todo 初始化自己项目需要的配置或者填充需要的业务逻辑 } }

输入结果:

信息: Could not instantiate TestExecutionListener class [org.springframework.test.context.web.ServletTestExecutionListener]. Specify custom listener classes or make the default listener classes (and their dependencies) available.
六月 18, 2018 10:45:30 上午 org.springframework.test.context.TestContextManager retrieveTestExecutionListeners
信息: Could not instantiate TestExecutionListener class [org.springframework.test.context.transaction.TransactionalTestExecutionListener]. Specify custom listener classes or make the default listener classes (and their dependencies) available.
六月 18, 2018 10:45:31 上午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [spring.xml]
六月 18, 2018 10:45:31 上午 org.springframework.context.support.GenericApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.GenericApplicationContext@6dde5c8c: startup date [Mon Jun 18 10:45:31 CST 2018]; root of context hierarchy
ioc容器初始化

这是在项目应用中经常会用到的小技巧,比如需要在容器初始化完成以后初始化某些必要的配置,我认为这是一种比较好的实现方式之一,后续要其它的方式会继续补充。

转载于:https://www.cnblogs.com/ChenXionghfut/p/9194863.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值