[英]Spring Boot external configuration and xml context
我想通过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}。
但这行不通。 在此先感谢您的帮助。
删除@PropertySource
就像Spring Boot已经完成的那样,而是添加@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
使用<context:property-placeholder/>
并导入基于xml的配置,如下所示:
@ImportResource({"classpath*:applicationContext.xml"})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.