how to set SqlMapClient outside of spring xmls

Posted by Omnipresent on Stack Overflow See other posts from Stack Overflow or by Omnipresent
Published on 2009-11-11T06:56:35Z Indexed on 2010/05/25 23:21 UTC
Read the original article Hit count: 313

Filed under:
|
|

I have the following in my xml configurations. I would like to convert these to my code because I am doing some unit/integration testing outside of the container.

xmls:

<bean id="MyMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
  <property name="configLocation" value="classpath:sql-map-config-oracle.xml"/>
  <property name="dataSource" ref="IbatisDataSourceOracle"/>
 </bean>

<bean id="IbatisDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="jdbc/my/mydb"/>
</bean>

code I used to fetch stuff from above xmls:

this.setSqlMapClient((SqlMapClient)ApplicationInitializer.getApplicationContext().getBean("MyMapClient"));

my code (for unit testing purposes):

SqlMapClientFactoryBean bean = new SqlMapClientFactoryBean();
UrlResource urlrc = new UrlResource("file:/data/config.xml");
bean.setConfigLocation(urlrc);
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("oracle.jdbc.OracleDriver");
dataSource.setUrl("jdbc:oracle:thin:@123.210.85.56:1522:ORCL");
dataSource.setUsername("dbo_mine");
dataSource.setPassword("dbo_mypwd");
bean.setDataSource(dataSource);

SqlMapClient sql = (SqlMapClient) bean; //code fails here

when the xml's are used then SqlMapClient is the class that sets up then how come I cant convert SqlMapClientFactoryBean to SqlMapClient

© Stack Overflow or respective owner

Related posts about java

Related posts about spring