[英]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.