Spring Boot外部配置和xml上下文

我想用Spring Boot外化我的配置,但我想继续部分使用我的xml上下文。

我的主要类SpringServerApplication.java:

@Configuration @PropertySources(value = {@PropertySource("classpath:/application.properties")}) public class SpringServerApplication { public static void main(String[] args) throws Exception { SpringApplication.run(new Object[] { SpringServerApplication.class, "classpath:ApplicationContextServer.xml" }, args); } } 

我把我的配置放在application.properties中。

在ApplicationContextServer.xml中,我想使用这样的参数:$ {user}。

但它不起作用。 在此先感谢您的帮助。

删除已经由Spring Boot完成的@PropertySource ,而是添加@EnableAutoConfiugration并使用@ImportResource导入xml配置文件。

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

这应该足以做你想要的。 根据xml文件中的内容,您甚至可以删除其中的一些内容(因为Spring Boot可以很容易地为您自动配置资源)。

applicationContext.xml使用

并导入基于xml的配置,如下所示:

 @ImportResource({"classpath*:applicationContext.xml"})