java - NoSuchBeanDefinitionException when using spring mvc with JPA -
severe: servlet.service() servlet [todoservlet] in context path [/todo] threw exception org.springframework.beans.factory.nosuchbeandefinitionexception: no qualifying bean of type [javax.persistence.entitymanagerfactory] defined @ org.springframework.beans.factory.beanfactoryutils.uniquebean(beanfactoryutils.java:432) @ org.springframework.beans.factory.beanfactoryutils.beanoftype(beanfactoryutils.java:379) @ org.springframework.orm.jpa.entitymanagerfactoryutils.findentitymanagerfactory(entitymanagerfactoryutils.java:111) @ org.springframework.orm.jpa.support.openentitymanagerinviewfilter.lookupentitymanagerfactory(openentitymanagerinviewfilter.java:229) @ org.springframework.orm.jpa.support.openentitymanagerinviewfilter.lookupentitymanagerfactory(openentitymanagerinviewfilter.java:205) @ org.springframework.orm.jpa.support.openentitymanagerinviewfilter.dofilterinternal(openentitymanagerinviewfilter.java:152) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:106) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:192) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:165) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:199) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:96) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:474) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:140) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:79) @ org.apache.catalina.valves.abstractaccesslogvalve.invoke(abstractaccesslogvalve.java:624) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:87) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:349) @ org.apache.coyote.http11.http11processor.service(http11processor.java:495) @ org.apache.coyote.abstractprocessorlight.process(abstractprocessorlight.java:66) @ org.apache.coyote.abstractprotocol$connectionhandler.process(abstractprotocol.java:767) @ org.apache.tomcat.util.net.nioendpoint$socketprocessor.dorun(nioendpoint.java:1347) @ org.apache.tomcat.util.net.socketprocessorbase.run(socketprocessorbase.java:49) @ java.util.concurrent.threadpoolexecutor.runworker(unknown source) @ java.util.concurrent.threadpoolexecutor$worker.run(unknown source) @ org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run(taskthread.java:61) @ java.lang.thread.run(unknown source)
web.xml
<!-- language: xml --> <code> <?xml version="1.0" encoding="utf-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" > <context-param> <param-name>contextconfiglocation</param-name> <param-value>classpath:/jpacontext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.contextloaderlistener</listener-class> </listener> <!-- jpa lazy --> <filter> <filter-name>springopenentitymanagerinviewfilter</filter-name> <filter-class>org.springframework.orm.jpa.support.openentitymanagerinviewfilter</filter-class> </filter> <filter-mapping> <filter-name>springopenentitymanagerinviewfilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <filter-name>springsecurityfilterchain</filter-name> <filter-class>org.springframework.web.filter.delegatingfilterproxy</filter-class> </filter> <filter-mapping> <filter-name>springsecurityfilterchain</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class>org.springframework.web.context.contextloaderlistener</listener-class> </listener> <context-param> <param-name>contextconfiglocation</param-name> <param-value>/web-inf/config/security-config.xml</param-value> </context-param> <servlet> <servlet-name>todoservlet</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <init-param> <param-name>contextconfiglocation</param-name> <param-value>/web-inf/config/servlet-config.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>todoservlet</servlet-name> <url-pattern>*.html</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>todoservlet</servlet-name> <url-pattern>*.json</url-pattern> </servlet-mapping> <display-name>archetype created web application</display-name> </web-app> </code>
jpacontext.xml
<!-- language: xml --> <code> <?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" xmlns:context="http://www.springframework.org/schema/context" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd"> <context:annotation-config/> <context:component-scan base-package="com.rockstars"/> <bean class="org.springframework.orm.jpa.support.persistenceannotationbeanpostprocessor"/> <bean id="entitymanagerfactory" class="org.springframework.orm.jpa.localcontainerentitymanagerfactorybean"> <property name="persistenceunitname" value="punit"/> <property name="datasource" ref="datasource"/> <property name="jpavendoradapter"> <bean class="org.springframework.orm.jpa.vendor.hibernatejpavendoradapter"> <property name="showsql" value="true" /> </bean> </property> <property name="jpapropertymap"> <map> <entry key="hibernate.dialect" value="org.hibernate.dialect.mysql5innodbdialect"/> <entry key="hibernate.hbm2ddl.auto" value="create"/> <entry key="hibernate.format_sql" value ="true"/> </map> </property> </bean> <bean id="transactionmanager" class="org.springframework.orm.jpa.jpatransactionmanager"> <property name="entitymanagerfactory" ref="entitymanagerfactory"/> </bean> <tx:annotation-driven transaction-manager="transactionmanager" /> <bean id="datasource" class="org.springframework.jdbc.datasource.drivermanagerdatasource"> <property name="driverclassname" value="com.mysql.jdbc.driver" /> <property name="url" value="jdbc:mysql://localhost:3306/organizer?autoreconnect=true"/> <property name="username" value = "root"/> <property name="password" value = "admin"/> </bean> </beans> </code>
pom.xml
<!--language: xml --> <code> <project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelversion>4.0.0</modelversion> <groupid>com.groupproject</groupid> <artifactid>todo</artifactid> <packaging>war</packaging> <version>0.0.1-snapshot</version> <name>todo maven webapp</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupid>junit</groupid> <artifactid>junit</artifactid> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-webmvc</artifactid> <version>3.2.16.release</version> </dependency> <dependency> <groupid>javax.servlet</groupid> <artifactid>servlet-api</artifactid> <version>2.5</version> <scope>provided</scope> </dependency> <dependency> <groupid>javax.servlet</groupid> <artifactid>jstl</artifactid> <version>1.2</version> </dependency> <dependency> <groupid>org.springframework.security</groupid> <artifactid>spring-security-taglibs</artifactid> <version>3.2.0.release</version> </dependency> <dependency> <groupid>org.springframework.security</groupid> <artifactid>spring-security-web</artifactid> <version>3.2.0.release</version> </dependency> <dependency> <groupid>org.springframework.security</groupid> <artifactid>spring-security-config</artifactid> <version>3.2.0.release</version> </dependency> <dependency> <groupid>org.codehaus.jackson</groupid> <artifactid>jackson-mapper-asl</artifactid> <version>1.4.1</version> </dependency> <dependency> <groupid>com.thoughtworks.xstream</groupid> <artifactid>xstream</artifactid> <version>1.3.1</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-oxm</artifactid> <version>3.2.0.release</version> </dependency> <dependency> <groupid>mysql</groupid> <artifactid>mysql-connector-java</artifactid> <version>5.1.21</version> </dependency> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-entitymanager</artifactid> <version>4.1.9.final</version> </dependency> <dependency> <groupid>javax.transaction</groupid> <artifactid>jta</artifactid> <version>1.1</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-jdbc</artifactid> <version>3.2.0.release</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-orm</artifactid> <version>3.2.0.release</version> </dependency> </dependencies> <build> <finalname>todo</finalname> </build> </project> </code>
entitymanagerfactory bean defined in jpacontext.xml compiler throws error. in advance.
try configuration. , there error in persistence.xml please share error.
<bean id="hibernatejpavendoradapter" class="org.springframework.orm.jpa.vendor.hibernatejpavendoradapter" /> <bean id="hibernatejpadialect" class="org.springframework.orm.jpa.vendor.hibernatejpadialect" /> <bean id="entitymanagerfactory" class="org.springframework.orm.jpa.localcontainerentitymanagerfactorybean"> <property name="datasource" ref="datasource" /> <property name="packagestoscan" value="com.test.entity" /> <property name="jpadialect" ref="hibernatejpadialect" /> <property name="jpavendoradapter" ref="hibernatejpavendoradapter" /> <property name="jpapropertymap"> <map> <entry key="hibernate.connection.driver_class" value="com.mysql.jdbc.driver" /> <entry key="hibernate.connection.url" value="jdbc:mysql://localhost:3306/online" /> <entry key="hibernate.connection.username" value="root" /> <entry key="hibernate.connection.password" value="root" /> <entry key="hibernate.dialect" value="org.hibernate.dialect.mysqldialect" /> <entry key="show_sql" value="true" /> <entry key="eclipselink.jdbc.exclusive-connection.is-lazy" value="true" /> </map> </property> </bean>
Comments
Post a Comment