Reputation: 45553
In a Spring 4 application, we are extending PropertySourcesPlaceholderConfigurer
to do some custom task during resolving properties.
To register our new class (MyPropertyConfigurer
) o Spring we use the following class:
@Configuration
public class AppConfig {
@Bean
public static PropertySourcesPlaceholderConfigurer
propertySourcesPlaceholderConfigurer() {
return new MyPropertyConfigurer();
}
}
As a matter of curiosity, can I add my new bean to Spring with spring.xml
instead of using the @Configuration
annotation?
Upvotes: 2
Views: 1362
Reputation: 1967
You can very well use a combination of both Spring based xml and java based config in your spring application.
You have to use
@ImportResource({"classpath:sampleapp.xml"})
along with
@Configuration
Look at the sample post below which explains it:
Mixing xml and java config with spring
Upvotes: 0
Reputation: 180
I had the same problem, my problem was fixed simply with placing the bean of my class in my Springbeans.xml
file like below:
<beans:bean class="MyPropertyConfigurer"/>
Upvotes: 2