开发者

Spring not initializing bean(dbunit); what have I missed?

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"/&g开发者_StackOverflowt;
                    <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:

  1. 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
  2. I have set breakpoints in my DBUnitBootstrapper class, but these are never caught, leading me to believe this bean doesn't get initialised.
  3. 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
  4. 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 insert

Have 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 :)


It seems to be you forgot to set a dataSource property in dbUnitBootstrapper

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜