2016-05-16 153 views
2

在Spring 4应用程序中,我们正在扩展PropertySourcesPlaceholderConfigurer在解析属性期间执行一些自定义任务。如何通过配置弹簧xml来延长弹簧

要注册Ø春季新的类(MyPropertyConfigurer)我们用下面的类:

@Configuration 
public class AppConfig { 
    @Bean 
    public static PropertySourcesPlaceholderConfigurer 
    propertySourcesPlaceholderConfigurer() { 
     return new MyPropertyConfigurer(); 
    } 

} 

由于好奇心的问题,我可以加我的新豆与spring.xml而不是使用@Configuration注释春天吗?

回答

2

我有同样的问题,我问题是简单地把我的班的豆放在我的中文件象下面这样:

<beans:bean class="MyPropertyConfigurer"/> 
0

在Spring应用程序中,您可以很好地使用基于Spring的xml和基于java的配置的组合。

你必须使用

@ImportResource({"classpath:sampleapp.xml"}) 

@Configuration 

先看样品后,低于该解释它沿着

Mixing xml and java config with spring

+0

是的,但我怎么能在'xml'定义'MyPropertyConfigurer'并把它作为'PropertySourcesPlaceholderConfigurer' –

+0

请参阅http://stackoverflow.com/questions/15502383/spring-loading -propertysourcesplaceholderconfigurer从 - JBoss的上下文 – shankarsh15