问题描述
我的applicaionContext.xml中有以下内容
I have following in my applicaionContext.xml
<bean id="IbatisDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@123.210.85.56:1522:ORCL"/>
<property name="username" value="mydb"/>
<property name="password" value="mydbpwd"/>
</bean>
<bean id="myMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="classpath:sql-map-config-oracle.xml"/>
<property name="dataSource" ref="IbatisDataSource"/>
</bean>
然后在我的代码中,我有:
then in my code I have:
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
SqlMapClient sqlclient = (SqlMapClient) ctx.getBean("myMapClient");
这样做会给我以下错误:
doing this gives me the following error:
我不明白为什么要找那个班?我正在尝试在容器外进行所有操作.因此,它甚至不应该在寻找该类...但是尽管如此,我还是试图寻找一个名为ASException的类,以便可以将其放在类路径中,但找不到我所在的ASException类.
I don't understand why is it looking for that class? I am trying to do everything outside the container. So it should not even be looking for that class...but nonetheless just to make it work I tried looking for class called ASException so I could put it on the classpath but no where can I find ASException class.
有指针吗?
堆栈跟踪和我的编译测试/运行测试库的图像
Images of stack trace and my compile test / run test libs
修改解决方案:即使我以为一切都在容器外...有一件东西不在容器外.
注意属性configLocation:
EditSolution:Even though I thought everything was outside the container...there was ONE thing that was not outside the container.
Notice the property configLocation:
<property name="configLocation" value="classpath:sql-map-config-oracle.xml"/>
sql-map-config-oracle.xml的实际内容为
actual content of sql-map-config-oracle.xml is
<sqlMapConfig>
<settings enhancementEnabled="true" useStatementNamespaces="true" />
<transactionManager type="JDBC">
<dataSource type="JNDI">
<property name="DataSource" value="my/jndi/mydb" />
</dataSource>
</transactionManager>
<sqlMap resource="somemapping.xml"/>
</sqlMapConfig>
JNDI的东西不需要在那里!
JNDI stuff does not need to be there!
sql-map-config-oracle.xml应该简单地是:
sql-map-config-oracle.xml should simply be:
<sqlMapConfig>
<settings enhancementEnabled="true" useStatementNamespaces="true" />
<sqlMap resource="somemapping.xml"/>
</sqlMapConfig>
推荐答案
您肯定有运行时依赖项问题,因为@Cletus表示 org.springframework.orm.ibatis.SqlMapClientFactoryBean
是使用编译的com.iplanet.ias.admin.common.ASException
,但现在您的类路径中没有它-Spring找不到它.您应该查看 SqlMapClientFactoryBean
的源代码,以查看调用 ASException
的位置-Spring应该有一个dist及其所有依赖项的dist,您也可以在执行此操作时在其中查找您的调查.
You definitely have a runtime dependency issue as @Cletus said org.springframework.orm.ibatis.SqlMapClientFactoryBean
was compiled with com.iplanet.ias.admin.common.ASException
but now you don't have it in your classpath -- Spring can't find it. You should Look at the source for SqlMapClientFactoryBean
to see where ASException
is called -- Spring should have a dist with all it's dependencies in it, you can also look in there when doing your investigation.
这篇关于实例化容器外部的春豆(用于测试)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!