我在使用Spring集成设置Stripes MVC的教程中遵循一些指导原则,我正在尝试集成DBUnit以在启动时初始化我的数据库,因此我不必浪费时间每次手动插入数据。 不幸的是,我无法将该教程与付费电子书相关联。
在我的web.xml中,我引用了Spring
<listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener>在我的applicationContext.xml中,我设置了以下bean
<bean id="dbUnitBootstrapper" class="com.jameselsey.salestracker.testing.DBUnitBootstrapper" init-method="execute"> <property name="enabled" value="true"/> <property name="operations"> <list> <bean class="org.dbunit.ant.Operation"> <property name="type" value="CLEAN_INSERT"/> <property name="src" value="classpath:testdata.xml"/> </bean> </list> </property> </bean> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="org.apache.derby.jdbc.ClientDriver"/> <property name="url" value="jdbc:derby://localhost:1527/salestracker"/> <property name="username" value="admin"/> <property name="password" value="admin"/> </bean>注意事项:
数据源与我的persistence.xml具有相同的细节,如果我手动插入数据,它会显示在我的应用程序中,因此连接细节应该没问题 我在我的DBUnitBootstrapper类中设置了断点,但这些断点从未被捕获,导致我相信这个bean没有被初始化。 testdata.xml文件存在于正确的位置,我有最简单的域对象,带有ID和一些String属性 在testdata.xml ,如果我将ID从1更改为abc我在控制台输出中得到一个numberFormatException ,所以听起来应用程序正在读取数据文件并尝试插入我错过了一些明显的东西吗 我还可以做些什么? 我在JavaRanch上问了这个问题,但到目前为止我还没有得到很多帮助。 这是个人学习项目,所以取得一些进展会很棒:)
I'm following some guidelines in a tutorial for setting up Stripes MVC with Spring integration, and I'm trying to integrate DBUnit to initialise my DB on startup so I don't have to waste time manually inserting data each time. Unfortunately I can't link the tutorial as its from a paid for eBook.
In my web.xml I have referenced Spring
<listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener>In my applicationContext.xml I have setup the following beans
<bean id="dbUnitBootstrapper" class="com.jameselsey.salestracker.testing.DBUnitBootstrapper" init-method="execute"> <property name="enabled" value="true"/> <property name="operations"> <list> <bean class="org.dbunit.ant.Operation"> <property name="type" value="CLEAN_INSERT"/> <property name="src" value="classpath:testdata.xml"/> </bean> </list> </property> </bean> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="org.apache.derby.jdbc.ClientDriver"/> <property name="url" value="jdbc:derby://localhost:1527/salestracker"/> <property name="username" value="admin"/> <property name="password" value="admin"/> </bean>Things to note:
The datasource has the same details as my persistence.xml, if I insert data manually it displays in my application, so the connection details should be fine I have set breakpoints in my DBUnitBootstrapper class, but these are never caught, leading me to believe this bean doesn't get initialised. the testdata.xml file exists in the correct place, I have the most simplest of domain objects with an ID and a few String attributes In the testdata.xml, if I change the ID from 1 to abc I get a numberFormatException in the console output, so it sounds like the application is reading the data file and trying to insertHave I missed something obvious? What else can I do? I have asked this question on JavaRanch but I haven't been able to get much assistance so far. This is for a personal learning project so it would be great to make some progress :)
最满意答案
您似乎忘了在dbUnitBootstrapper设置dataSource属性
It seems to be you forgot to set a dataSource property in dbUnitBootstrapper
更多推荐
发布评论