English 中文(简体)
instantiating spring bean outside the container (for testing)
原标题:

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:

Error creating bean with name myMapClient defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: com/iplanet/ias/admin/common/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.

Any pointers?

Images of stack trace and my compile test / run test libs alt text alt text alt text

Edit Solution: 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"/>

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 stuff does not need to be there!

sql-map-config-oracle.xml should simply be:

<sqlMapConfig>
   <settings enhancementEnabled="true" useStatementNamespaces="true" />
        <sqlMap resource="somemapping.xml"/>
</sqlMapConfig>
最佳回答

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.

问题回答

This class was found during compilation but not during running:

com/iplanet/ias/admin/common/ASException

So when you re running the program, it can t seem to find this class, which belongs to the Sun app or portal server that you re using. In short: it s a classpath error.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签