Announcement Announcement Module
Collapse
No announcement yet.
Spring Not Seeing Transaction Manager Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Not Seeing Transaction Manager

    Hi,
    I have been pulling my hair out trying to get a basic JPA example (written by no less than Rod Johnson himself to work ) for the last two days .

    The latest attempt is I have integrated the example with a working MVC example but I can't get past an error with it not seeing the Transaction Manager. The error message is at the bottom of the post.

    Other people with this problem say it is the persistence.xml not being in the META-INF directory . This is not what is causing the problem .

    I believe the version of spring I am using is 1.2.9

    If anybody can help ,
    Thanks
    Paul


    This is my persistence.xml file in META-INF


    <?xml version="1.0" encoding="UTF-8"?>
    <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
    <persistence-unit name="BIS" transaction-type="RESOURCE-LOCAL">
    <class>springmvc.model.Book</class>
    </persistence-unit>
    </persistence>


    This is the configuration file:


    <?xml version="1.0" encoding="UTF-8"?>

    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schem...-beans-2.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"
    >

    <bean name="/hello_world.html" class="springmvc.web.HelloWorldController"/>
    <bean name="/list_cars.html" class="springmvc.web.CarListController"/>
    <bean name="/add_book.html" class="springmvc.web.AddBookController"/>
    <bean id="viewResolver" class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlVi ew"/>
    <property name="prefix" value="/jsp/"/>
    <property name="suffix" value=".jsp"/>
    </bean>
    <!--
    NEW SHIT
    -->


    <bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerE ntityManagerFactoryBean">
    <property name="persistenceUnitName" value="BIS"/>
    <property name="dataSource" ref="dataSource" />
    <property name="jpaVendorAdapter" ref="vendorAdapter"/>
    </bean>

    <bean id="dataSource" class= "org.apache.commons.dbcp.BasicDatasource">

    <property name="toplink.jdbc.url" value="jdbc:mysql://localhost:3307/test"/>

    <property name="toplink.jdbc.user" value="root"/>
    <property name="toplink.jdbc.driver" value="com.mysql.jdbc.Driver"/>
    <property name="toplink.jdbc.password" value=""/>
    <property name="toplink.ddl-generation" value="drop-and-create-tables"/>

    </bean>
    <bean id ="vendorAdapter" class="org.springframework.orm.jpa.vendor.TopLinkJ paVendorAdapter">
    <property name="showSQL" value="true"/>
    <property name="generateDdl" value="true"/>
    </bean>

    <bean class="springmvc.service.BookInventorySystem"/>

    <bean id="transactionManager"
    class="org.springframework.orm.jpa.JpaTransactionM anager">

    <property name="entitityManagerFactory" ref="entityManagerFactory" />
    </bean>

    <bean class="org.springframework.orm.jpa.support.Persist enceAnnotationBeanPostProcessor" />
    <tx:annotation-driven/>
    </beans>

    This is the error


    SEVERE: StandardWrapper.Throwable
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name '/hello_world.html' defined in ServletContext resource [/WEB-INF/springmvc-servlet.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.transaction.config.internalTr ansactionAdvisor': Cannot create inner bean '(inner bean)' of type [org.springframework.transaction.interceptor.Transa ctionInterceptor] while setting bean property 'transactionInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'transactionManager' defined in ServletContext resource [/WEB-INF/springmvc-servlet.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/persistence/PersistenceException
    Related cause: org.springframework.beans.factory.CannotLoadBeanCl assException: Cannot find class [org.apache.commons.dbcp.BasicDatasource] for bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/springmvc-servlet.xml]; nested exception is java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDatasource

  • #2
    When posting code use [ code][/code ] tags, that way it remains readable.

    Read your stacktrace that tells you exactly what is going on...

    Code:
    Cannot find class [org.apache.commons.dbcp.BasicDatasource] for bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/springmvc-servlet.xml]; nested exception is java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDatasource
    Include the commons-dbcp.jar in your classpath it is missing...

    Again read your stacktrace before comming to the wrong conclusions.

    Comment


    • #3
      Thank you Marten .

      I'll remember to use the code brackets.

      Comment

      Working...
      X