![](/img/trans.png)
[英]Spring - “context:property-placeholder” - property priority
[英]java spring context:property-placeholder manually loading
Spring java- quartz schedular应用程序
我想加载.property文件动态传递throw程序参数而不是context:property-placeholder在spring上下文中,我该如何实现这个任务,任何帮助都赞赏...
我从主java文件手动加载和刷新spring上下文,如下面的代码所示。
SpringUtil_1.loadSpringConfig();
rootContext = new ClassPathXmlApplicationContext();
rootContext.setConfigLocation("abc-configuration.xml");
rootContext.refresh();
在spring配置中,我有如下所示的上下文属性占位符,我想从代码中获取。
<context:property-placeholder location="classpath:lnRuntime.properties"/>
我在spring上下文和使用spring EL的java文件中使用占位符如下
<bean id="dataSource"
class="org.springframework.jdbc.datasource.SingleConnectionDataSource">
<property name="driverClassName" value="net.sourceforge.jtds.jdbcx.JtdsDataSource"/>
<property name="url" value="${dataSource.url}"/>
</bean>
在java中我正在访问如下
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;
}
Resoruces http://www.baeldung.com/2012/02/06/properties-with-spring/#byhandnew
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.