Hi,
I'm trying to replace a placeholder in my xml spring configuration file. In the manual I read about PropertyPlaceholderConfigurer but allways with XMLBeanFactory. Documention says that should use ApplicationContext in a J2EE environment so I tried the following:
Relevant part in springconfig.xml locks likeCode:... ClassPathXmlApplicationContext appctx = new ClassPathXmlApplicationContext("springconfig.xml"); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); Properties p = new Properties(); p.setProperty("jdbc.tnsname", "SOMENAME"); cfg.setProperties(p); cfg.postProcessBeanFactory(appctx.getBeanFactory()); appctx.refresh(); ...
AfterCode:... <bean id="DS_GASX" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /> <property name="url" value="jdbc:oracle:oci8:@${jdbc.tnsname}" /> <property name="username" value="ABC" /> <property name="password" value="XYZ" /> </bean> ... <bean id="SF_HIBERNATE" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="DS_GASX" /> ...
Spring is trying to initialize Hibernate. A JDBC Exception is throws because the placeholder is still there and there is no TNS entry with this name.Code:ClassPathXmlApplicationContext appctx = new ClassPathXmlApplicationContext("springconfig.xml");
After
I see some output in the logs saying "Resolved placeholder 'jdbc.tnsname' to value [SOMENAME]". After appctx.refresh() the initialization of hibernate still fails with the same JDBC TNS error. I tried it with appctx.refresh() and without. Everytime the same. I debugged a little in LocalDataSourceConnectionProvider and saw that the URL in the Connection still has the placeholder.Code:cfg.postProcessBeanFactory(appctx.getBeanFactory());
What is wrong? Is there an other way to do this? I can't use PropertyOverrideConfigurer because I dont have the needed propertie value there.
Tanks in advance.
Alex


Reply With Quote