Spring java- quartz schedular application
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...
I am manually loading and refreshing spring context from main java file as illustrate by following code.
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.
<context:property-placeholder location="classpath:lnRuntime.properties"/>
i am using place holders in spring context and java file using spring EL as follows
<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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.