加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

java-Spring @Configuration的属性

发布时间:2020-12-15 01:21:13 所属栏目:大数据 来源:网络整理
导读:如果我有一个通过XML文件发送的PropertyPlaceholderConfigurer,是否可以让Spring @Configuration使用它作为它处理的所有bean的属性源? @Configuration@ComponentScan(value = { "x.y.z })@ImportResource({ "classpath:remote-properties/applicationContex

如果我有一个通过XML文件发送的PropertyPlaceholderConfigurer,是否可以让Spring @Configuration使用它作为它处理的所有bean的属性源?

@Configuration
@ComponentScan(value = { "x.y.z })
@ImportResource({ "classpath:remote-properties/applicationContext.xml",})
public class CoreConfiguration implements TransactionManagementConfigurer {

    @Resource(name = "com.c.h.c.PropertyPlaceholderConfigurer")
    public PropertyPlaceholderConfigurer pp;

   @Bean
    public PropertyPlaceholderConfigurer propertiesFactoryBean() {
        return pp;
    }
}

有了上面的内容,它永远不会碰到pp上的断点.如果删除@Bean和方法,则可以验证是否填充了pp.那么如何在配置中注册呢?

最佳答案
我觉得很傻.我在@Value注释之一上缺少右花括号.我无法想象我看了多少次却错过了.

因此,在您@ImportResource所在的应用程序上下文中使用PropertyPlaceHolderConfigurer可以正常工作.您甚至不需要将其作为@Resource引入.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读