d-m*_*man 3 java spring properties 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();
Run Code Online (Sandbox Code Playgroud)
在spring配置中,我有如下所示的上下文属性占位符,我想从代码中获取.
<context:property-placeholder location="classpath:lnRuntime.properties"/>
Run Code Online (Sandbox Code Playgroud)
我在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>
Run Code Online (Sandbox Code Playgroud)
在java中我正在访问如下
private @Value("${dz.host}") String dzHost;
Run Code Online (Sandbox Code Playgroud)
找到答案
@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;
}
Run Code Online (Sandbox Code Playgroud)
Resoruces http://www.baeldung.com/2012/02/06/properties-with-spring/#byhandnew
| 归档时间: |
|
| 查看次数: |
1900 次 |
| 最近记录: |