I've been struggling with this for past couple of days. I am trying to test a DAO outside the container but while running the test case I am getting the error:
Error creating bean with name 'SqlMapClient' 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'm using NB to run the tests. people have been saying that I need the above class to be in the run time class path of the test case. However, I am absolutely unable to find where actually that jar is...?? I've included all that jars that are on my containers classpath + jars in my projects lib folder to the runtime classpath of the Unit test. Still I get the same error.
Also googling for this JAR didnt work either.
Maybe someone out there knows where to get this freakin jar from. And hopefully that fixed my problems.
This doesn't directly answer your question but I have two advices. First, now that I know that you are using Spring, I'd suggest to stop using your own ServiceLocator
to lookup the JNDI datasource as you mentioned in a previous question. Instead, you should use Spring facilities for that and then inject the datasource into yours beans. To get a JDNI datasource, use Spring's JndiObjectFactoryBean
, something like that:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:/comp/env/jdbc/myDS</value>
</property>
</bean>
Then, when running outside the container (typically when running tests), my advice would be to not use a JNDI datasource. Instead, you should use Spring facilities to provide a datasource to your DAOs in another way (e.g. using a DriverManagerDataSource
, you don't need a real connection pool when running tests). This would allow you to run your tests without having to start iPlanet which makes sense for testing (and you don't want to test iPlanet's connection pool, you want to test your DAOs).
So, create an applicationContext-test.xml
to be used during testing with another configuration for the data access. Below, a sample configuration for the DriverManagerDataSource
:
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="..."/>
<property name="url" value="..."/>
<property name="username" value="..."/>
<property name="password" value="..."/>
</bean>
This is really the recommended approach (check the chapter Data access using JDBC for more details on the different options).
PS: I have no idea from where com/iplanet/ias/admin/common/ASException
comes from but it is obviously one of iPlanet itself. If you really want to find out, search in all jars of your iPlanet install, especially the one referenced in its startup script. But I think that' you'll face JNDI issues after that, be warned.