如何通过配置弹簧xml来延长弹簧
问题描述:
在Spring 4应用程序中,我们正在扩展PropertySourcesPlaceholderConfigurer
在解析属性期间执行一些自定义任务。如何通过配置弹簧xml来延长弹簧
要注册Ø春季新的类(MyPropertyConfigurer
)我们用下面的类:
@Configuration
public class AppConfig {
@Bean
public static PropertySourcesPlaceholderConfigurer
propertySourcesPlaceholderConfigurer() {
return new MyPropertyConfigurer();
}
}
由于好奇心的问题,我可以加我的新豆与spring.xml
而不是使用@Configuration
注释春天吗?
答
我有同样的问题,我问题是简单地把我的班的豆放在我的中文件象下面这样:
<beans:bean class="MyPropertyConfigurer"/>
答
在Spring应用程序中,您可以很好地使用基于Spring的xml和基于java的配置的组合。
你必须使用
@ImportResource({"classpath:sampleapp.xml"})
与
@Configuration
先看样品后,低于该解释它沿着
:
是的,但我怎么能在'xml'定义'MyPropertyConfigurer'并把它作为'PropertySourcesPlaceholderConfigurer' –
请参阅http://stackoverflow.com/questions/15502383/spring-loading -propertysourcesplaceholderconfigurer从 - JBoss的上下文 – shankarsh15