[英]java spring context:property-placeholder manually loading
Spring java- quartz schedular application Spring java- quartz schedular应用程序
I want to load .property file dynamically passed throw program parameter instead of context:property-placeholder in spring context, how can i achieve this task, any help appreciated... 我想加载.property文件动态传递throw程序参数而不是context:property-placeholder在spring上下文中,我该如何实现这个任务,任何帮助都赞赏...
I am manually loading and refreshing spring context from main java file as illustrate by following code. 我从主java文件手动加载和刷新spring上下文,如下面的代码所示。
SpringUtil_1.loadSpringConfig();
rootContext = new ClassPathXmlApplicationContext();
rootContext.setConfigLocation("abc-configuration.xml");
rootContext.refresh();
In spring configuration i have context property place holder as follows which i want to from code. 在spring配置中,我有如下所示的上下文属性占位符,我想从代码中获取。
<context:property-placeholder location="classpath:lnRuntime.properties"/>
i am using place holders in spring context and java file using spring EL as follows 我在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>
and in java i am accesing as follows 在java中我正在访问如下
private @Value("${dz.host}") String dzHost;
Found answer 找到答案
@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 Resoruces http://www.baeldung.com/2012/02/06/properties-with-spring/#byhandnew
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.