Why can I run JUnit tests for my Spring project, but not a main method?
Posted
by FarmBoy
on Stack Overflow
See other posts from Stack Overflow
or by FarmBoy
Published on 2010-05-21T20:55:30Z
Indexed on
2010/05/21
21:20 UTC
Read the original article
Hit count: 441
I am using JDBC to connect to MySQL for a small application. In order to test without altering the real database, I'm using HSQL in memory for JUnit tests.
I'm using Spring for DI and DAOs. Here is how I'm configuring my HSQL DataSource
<bean id="mockDataSource" class="org.springframework.jdbc.datasource.SingleConnectionDataSource">
<property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
<property name="url" value="jdbc:hsqldb:mem:mockSeo"/>
<property name="username" value="sa"/>
</bean>
This works fine for my JUnit tests which use the mock DB. But when I try to run a main method, I find the following error:
Error creating bean with name 'mockDataSource' defined in class path resource [beans.xml]:
Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException:
Could not load JDBC driver class [org.hsqldb.jdbcDriver]
I'm running from Eclipse, and I'm using the Maven plugin. Is there a reason why this would work as a Test, but not as a main()
? I know that the main
method itself is not the problem, because it works if I remove all references to the HSQL DataSource from my Spring Configuration file.
© Stack Overflow or respective owner