我在我的xml配置中有以下内容。我想将这些转换为我的代码,因为我正在容器外进行一些单元/集成测试。如何在Spring xmls之外设置SqlMapClient
个XML:
<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>
代码我用来获取上述个XML的东西:
this.setSqlMapClient((SqlMapClient)ApplicationInitializer.getApplicationContext().getBean("MyMapClient"));
我的代码(单元测试):
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
当XML的是那么使用SqlMapClient
就是设置的类然后我怎么不能转换SqlMapClientFactoryBean
SqlMapClient
你在第二段提到你能告诉我该怎么做?或链接?我发现为了测试的目的而制作单独的xmls',但是应该在那里做什么?最后,我必须能够将SqlMapClient传递给setSqlMapClient(..),因为我的DAO使用的是getSqlMapClientTemplate()。 – Omnipresent 2009-11-11 13:09:39
如何创建SqlMapClient的非弹簧方式?我想这就是我想通过舍弃XML来尝试做的事情。 ..care显示一些代码? – Omnipresent 2009-11-11 13:26:34