Spring Boot外部配置和xml上下文 [英] Spring Boot external configuration and xml context
问题描述
我想用Spring Boot外化我的配置,但我想继续部分使用我的xml上下文。
我的主类SpringServerApplication.java:
@Configuration
@PropertySources(value = {@PropertySource(classpath:/application.properties)})
公共类SpringServerApplication {
public static void main(String [] args)throws Exception {
SpringApplication.run(new Object [] {
SpringServerApplication.class,classpath: ApplicationContextServer.xml},args);
}
}
我将配置放在应用程序中。属性。
在ApplicationContextServer.xml中,我想使用这样的参数:$ {user}。
<但是它不起作用。在此先感谢您的帮助。
删除 @PropertySource
为这已经由Spring Boot完成了,而是添加 @EnableAutoConfiugration
并使用 @ImportResource
来导入你的xml配置文件。 / p>
@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可以很容易地为您自动配置资源)。
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 :
@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);
}
}
I put my configuration in application.properties.
And in ApplicationContextServer.xml, I want to use some parameter like this : ${user}.
But it does not work. Thanks in advance for your help.
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).
这篇关于Spring Boot外部配置和xml上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!