JavaSpring上下文:手动加载属性占位符
SpringJava-quartz调度应用程序 我想加载动态传递的.property文件,抛出程序参数,而不是context:property占位符在spring上下文中,如何实现此任务,欢迎任何帮助… 我正在从主java文件手动加载和刷新spring上下文,如下代码所示JavaSpring上下文:手动加载属性占位符,java,spring,properties,loading,Java,Spring,Properties,Loading,SpringJava-quartz调度应用程序 我想加载动态传递的.property文件,抛出程序参数,而不是context:property占位符在spring上下文中,如何实现此任务,欢迎任何帮助… 我正在从主java文件手动加载和刷新spring上下文,如下代码所示 SpringUtil_1.loadSpringConfig(); rootContext = new ClassPathXmlApplicationContext(); rootContext.setConfigLocatio
SpringUtil_1.loadSpringConfig();
rootContext = new ClassPathXmlApplicationContext();
rootContext.setConfigLocation("abc-configuration.xml");
rootContext.refresh();
在spring配置中,我有上下文属性placeholder,如下所示,我想从代码中删除它
<context:property-placeholder location="classpath:lnRuntime.properties"/>
找到答案
@Bean
public static PropertySourcesPlaceholderConfigurer properties(){
PropertySourcesPlaceholderConfigurer pspc =
new PropertySourcesPlaceholderConfigurer();
Resource[] resources = new ClassPathResource[ ]
{ new ClassPathResource( "foo.properties" ) };
pspc.setLocations( resources );
//pspc.setIgnoreUnresolvablePlaceholders( true );
return pspc;
}
决议
private @Value("${dz.host}") String dzHost;
@Bean
public static PropertySourcesPlaceholderConfigurer properties(){
PropertySourcesPlaceholderConfigurer pspc =
new PropertySourcesPlaceholderConfigurer();
Resource[] resources = new ClassPathResource[ ]
{ new ClassPathResource( "foo.properties" ) };
pspc.setLocations( resources );
//pspc.setIgnoreUnresolvablePlaceholders( true );
return pspc;
}