簡體   English   中英

Spring Boot外部配置和xml上下文

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM