Spring Boot external configuration and xml context

后端 未结 2 2038
失恋的感觉
失恋的感觉 2021-01-16 05:20

I want to externalize my configuration with Spring Boot, but I want to continue to partially use my xml context.

My main class SpringServerApplication.java :

相关标签:
2条回答
  • 2021-01-16 05:31

    Use <context:property-placeholder/> in applicationContext.xml

    And import xml based configuration like this:

    @ImportResource({"classpath*:applicationContext.xml"})
    
    0 讨论(0)
  • 2021-01-16 05:43

    Remove the @PropertySource as that is already done by Spring Boot, instead add @EnableAutoConfiugration and use @ImportResource to import your xml config files.

    @Configuration
    @EnableAutoConfiguration
    @ImportResource("classpath:ApplicationContextServer.xml")
    public class SpringServerApplication {
    
        public static void main(String[] args) throws Exception {
            SpringApplication.run(new Object[] {SpringServerApplication.class}, args);
        }
    }
    

    That should be enough to do what you want. Depending on the content in your xml file you might even be able to drop some of it (as Spring Boot can quite easily do auto configuration of resources for you).

    0 讨论(0)
提交回复
热议问题