java - spring error :org.springframework.web.context.ContextLoader - Context initialization failed -
i developing simple project in spring have following problem org.springframework.web.context.contextloader - context initialization failed controller:
package com.linedata.jaba.controllers; import org.springframework.beans.factory.annotation.autowired; import org.springframework.stereotype.controller; import org.springframework.web.bind.annotation.requestmapping; import com.linedata.jaba.metier.ibanquemetier; @controller public class banquecontroller { @autowired private ibanquemetier metier; @requestmapping(value="/index") public string index() { return "banque"; } }
persistence.xml file
<?xml version="1.0" encoding="utf-8"?> <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> <persistence-unit name="persistance_unit" transaction-type="resource_local"> <provider>org.hibernate.ejb.hibernatepersistence</provider> <properties> <property name="hibernate.show_sql" value="true" /> <property name="hibernate.hbm2ddl.auto" value="create" /><!-- create or update --> </properties> </persistence-unit> </persistence>
applicationcontext.xml
<?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.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd"> <bean id="dao" class="com.linedata.jaba.dao.banquedaoimp"> </bean> <bean id="metier" class="com.linedata.jaba.metier.banquemetierimp"> <property name="dao" ref="dao"></property> </bean> <bean id="datasource" class="org.springframework.jdbc.datasource.drivermanagerdatasource"> <property name="driverclassname" value="com.mysql.jdbc.driver"></property> <property name="url" value="jdbc:mysql://localhost:3306/banque"> </property> <property name="username" value="root"></property> <property name="password" value=""></property> </bean> <bean id="persistenceunitmanager" class="org.springframework.orm.jpa.persistenceunit.defaultpersistenceunitmanager"> <property name="persistencexmllocations"> <list> <value>classpath*:meta-inf/persistence.xml </value> </list> </property> <property name="defaultdatasource" ref="datasource"></property> </bean> <bean id="entitymanagerfactory" class="org.springframework.orm.jpa.localcontainerentitymanagerfactorybean"> <property name="persistenceunitmanager" ref="persistenceunitmanager"> </property> <property name="persistenceunitname" value="persistance_unit"></property> </bean> <bean id="transactionmanager" class="org.springframework.orm.jpa.jpatransactionmanager"> <property name="entitymanagerfactory" ref="entitymanagerfactory"></property> </bean> <tx:annotation-driven transaction-manager="transactionmanager" /> <context:annotation-config></context:annotation-config> </beans>
web.xml file
<?xml version="1.0" encoding="utf-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <context-param> <param-name>contextconfiglocation</param-name> <param-value>classpath*:applicationcontext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.contextloaderlistener</listener-class> </listener> <servlet> <servlet-name>appservlet</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <init-param> <param-name>contextconfiglocation</param-name> <param-value>/web-inf/spring/appservlet/servlet-context.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>appservlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>
stack trace
19 août 2015 16:16:12 org.apache.catalina.core.aprlifecyclelistener init info: apr based apache tomcat native library allows optimal performance in production environments not found on java.library.path: c:\program files\java\jre6\bin;c:\windows\sun\java\bin;c:\windows\system32;c:\windows;c:/program files/java/jre6/bin/server;c:/program files/java/jre6/bin;c:/program files/java/jre6/lib/amd64;c:\program files\java\jre6\bin;c:\oracle\product\10.2.0\db_7\bin;c:\oracle\product\10.2.0\db_1\bin;c:\windows\system32;c:\windows;c:\windows\system32\wbem;c:\windows\system32\windowspowershell\v1.0\;c:\program files (x86)\intel\opencl sdk\3.0\bin\x86;c:\program files (x86)\intel\opencl sdk\3.0\bin\x64;c:\xampp\php;c:\xampp\php\zendframework\library;c:\program files\nodejs\;c:\program files (x86)\heroku\bin;c:\program files (x86)\git\cmd;c:\program files (x86)\miktex 2.9\miktex\bin\;c:\program files\java\jre6\bin;c:\program files (x86)\steel bank common lisp\1.0.53\;c:\users\asus\appdata\roaming\npm;c:\users\asus\desktop\eclipse;;. 19 août 2015 16:16:12 org.apache.tomcat.util.digester.setpropertiesrule begin attention: [setpropertiesrule]{server/service/engine/host/context} setting property 'source' 'org.eclipse.jst.jee.server:stage' did not find matching property. 19 août 2015 16:16:12 org.apache.coyote.http11.http11protocol init info: initialisation de coyote http/1.1 sur http-8080 19 août 2015 16:16:12 org.apache.catalina.startup.catalina load info: initialization processed in 642 ms 19 août 2015 16:16:13 org.apache.catalina.core.standardservice start info: démarrage du service catalina 19 août 2015 16:16:13 org.apache.catalina.core.standardengine start info: starting servlet engine: apache tomcat/6.0.44 19 août 2015 16:16:13 org.apache.catalina.core.applicationcontext log info: initializing spring root webapplicationcontext info : org.springframework.web.context.contextloader - root webapplicationcontext: initialization started info : org.springframework.web.context.support.xmlwebapplicationcontext - refreshing root webapplicationcontext: startup date [wed aug 19 16:16:13 cest 2015]; root of context hierarchy info : org.springframework.beans.factory.xml.xmlbeandefinitionreader - loading xml bean definitions url [file:/c:/users/asus/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/stage/web-inf/classes/applicationcontext.xml] info : org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor - jsr-330 'javax.inject.inject' annotation found , supported autowiring info : org.springframework.beans.factory.support.defaultlistablebeanfactory - pre-instantiating singletons in org.springframework.beans.factory.support.defaultlistablebeanfactory@18abe654: defining beans [dao,metier,datasource,persistenceunitmanager,entitymanagerfactory,transactionmanager,org.springframework.aop.config.internalautoproxycreator,org.springframework.transaction.annotation.annotationtransactionattributesource#0,org.springframework.transaction.interceptor.transactioninterceptor#0,org.springframework.transaction.config.internaltransactionadvisor,org.springframework.context.annotation.internalconfigurationannotationprocessor,org.springframework.context.annotation.internalautowiredannotationprocessor,org.springframework.context.annotation.internalrequiredannotationprocessor,org.springframework.context.annotation.internalcommonannotationprocessor,org.springframework.context.annotation.internalpersistenceannotationprocessor,org.springframework.context.annotation.configurationclasspostprocessor$importawarebeanpostprocessor#0]; root of factory hierarchy info : org.springframework.beans.factory.support.defaultlistablebeanfactory - destroying singletons in org.springframework.beans.factory.support.defaultlistablebeanfactory@18abe654: defining beans [dao,metier,datasource,persistenceunitmanager,entitymanagerfactory,transactionmanager,org.springframework.aop.config.internalautoproxycreator,org.springframework.transaction.annotation.annotationtransactionattributesource#0,org.springframework.transaction.interceptor.transactioninterceptor#0,org.springframework.transaction.config.internaltransactionadvisor,org.springframework.context.annotation.internalconfigurationannotationprocessor,org.springframework.context.annotation.internalautowiredannotationprocessor,org.springframework.context.annotation.internalrequiredannotationprocessor,org.springframework.context.annotation.internalcommonannotationprocessor,org.springframework.context.annotation.internalpersistenceannotationprocessor,org.springframework.context.annotation.configurationclasspostprocessor$importawarebeanpostprocessor#0]; root of factory hierarchy error: org.springframework.web.context.contextloader - context initialization failed org.springframework.beans.factory.beancreationexception: error creating bean name 'dao': injection of persistence dependencies failed; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'entitymanagerfactory' defined in url [file:/c:/users/asus/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/stage/web-inf/classes/applicationcontext.xml]: invocation of init method failed; nested exception java.lang.illegalargumentexception: no persistence unit name 'persistance_unit' found @ org.springframework.orm.jpa.support.persistenceannotationbeanpostprocessor.postprocesspropertyvalues(persistenceannotationbeanpostprocessor.java:342) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.populatebean(abstractautowirecapablebeanfactory.java:1106) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:517) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:456) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:294) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:225) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:291) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:193) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:585) @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:913) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:464) @ org.springframework.web.context.contextloader.configureandrefreshwebapplicationcontext(contextloader.java:385) @ org.springframework.web.context.contextloader.initwebapplicationcontext(contextloader.java:284) @ org.springframework.web.context.contextloaderlistener.contextinitialized(contextloaderlistener.java:111) @ org.apache.catalina.core.standardcontext.listenerstart(standardcontext.java:4210) @ org.apache.catalina.core.standardcontext.start(standardcontext.java:4709) @ org.apache.catalina.core.containerbase.start(containerbase.java:1060) @ org.apache.catalina.core.standardhost.start(standardhost.java:822) @ org.apache.catalina.core.containerbase.start(containerbase.java:1060) @ org.apache.catalina.core.standardengine.start(standardengine.java:463) @ org.apache.catalina.core.standardservice.start(standardservice.java:525) @ org.apache.catalina.core.standardserver.start(standardserver.java:759) @ org.apache.catalina.startup.catalina.start(catalina.java:595) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ org.apache.catalina.startup.bootstrap.start(bootstrap.java:289) @ org.apache.catalina.startup.bootstrap.main(bootstrap.java:414) caused by: org.springframework.beans.factory.beancreationexception: error creating bean name 'entitymanagerfactory' defined in url [file:/c:/users/asus/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/stage/web-inf/classes/applicationcontext.xml]: invocation of init method failed; nested exception java.lang.illegalargumentexception: no persistence unit name 'persistance_unit' found @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1455) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:519) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:456) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:294) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:225) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:291) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:193) @ org.springframework.orm.jpa.support.persistenceannotationbeanpostprocessor.finddefaultentitymanagerfactory(persistenceannotationbeanpostprocessor.java:530) @ org.springframework.orm.jpa.support.persistenceannotationbeanpostprocessor.findentitymanagerfactory(persistenceannotationbeanpostprocessor.java:496) @ org.springframework.orm.jpa.support.persistenceannotationbeanpostprocessor$persistenceelement.resolveentitymanager(persistenceannotationbeanpostprocessor.java:657) @ org.springframework.orm.jpa.support.persistenceannotationbeanpostprocessor$persistenceelement.getresourcetoinject(persistenceannotationbeanpostprocessor.java:630) @ org.springframework.beans.factory.annotation.injectionmetadata$injectedelement.inject(injectionmetadata.java:150) @ org.springframework.beans.factory.annotation.injectionmetadata.inject(injectionmetadata.java:87) @ org.springframework.orm.jpa.support.persistenceannotationbeanpostprocessor.postprocesspropertyvalues(persistenceannotationbeanpostprocessor.java:339) ... 28 more caused by: java.lang.illegalargumentexception: no persistence unit name 'persistance_unit' found @ org.springframework.orm.jpa.persistenceunit.defaultpersistenceunitmanager.obtainpersistenceunitinfo(defaultpersistenceunitmanager.java:535) @ org.springframework.orm.jpa.localcontainerentitymanagerfactorybean.determinepersistenceunitinfo(localcontainerentitymanagerfactorybean.java:287) @ org.springframework.orm.jpa.localcontainerentitymanagerfactorybean.createnativeentitymanagerfactory(localcontainerentitymanagerfactorybean.java:239) @ org.springframework.orm.jpa.abstractentitymanagerfactorybean.afterpropertiesset(abstractentitymanagerfactorybean.java:310) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.invokeinitmethods(abstractautowirecapablebeanfactory.java:1514) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1452) ... 41 more 19 août 2015 16:16:16 org.apache.catalina.core.standardcontext listenerstart grave: exception lors de l'envoi de l'évènement contexte initialisé (context initialized) à l'instance de classe d'écoute (listener) org.springframework.web.context.contextloaderlistener org.springframework.beans.factory.beancreationexception: error creating bean name 'dao': injection of persistence dependencies failed; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'entitymanagerfactory' defined in url [file:/c:/users/asus/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/stage/web-inf/classes/applicationcontext.xml]: invocation of init method failed; nested exception java.lang.illegalargumentexception: no persistence unit name 'persistance_unit' found @ org.springframework.orm.jpa.support.persistenceannotationbeanpostprocessor.postprocesspropertyvalues(persistenceannotationbeanpostprocessor.java:342) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.populatebean(abstractautowirecapablebeanfactory.java:1106) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:517) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:456) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:294) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:225) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:291) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:193) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:585) @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:913) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:464) @ org.springframework.web.context.contextloader.configureandrefreshwebapplicationcontext(contextloader.java:385) @ org.springframework.web.context.contextloader.initwebapplicationcontext(contextloader.java:284) @ org.springframework.web.context.contextloaderlistener.contextinitialized(contextloaderlistener.java:111) @ org.apache.catalina.core.standardcontext.listenerstart(standardcontext.java:4210) @ org.apache.catalina.core.standardcontext.start(standardcontext.java:4709) @ org.apache.catalina.core.containerbase.start(containerbase.java:1060) @ org.apache.catalina.core.standardhost.start(standardhost.java:822) @ org.apache.catalina.core.containerbase.start(containerbase.java:1060) @ org.apache.catalina.core.standardengine.start(standardengine.java:463) @ org.apache.catalina.core.standardservice.start(standardservice.java:525) @ org.apache.catalina.core.standardserver.start(standardserver.java:759) @ org.apache.catalina.startup.catalina.start(catalina.java:595) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ org.apache.catalina.startup.bootstrap.start(bootstrap.java:289) @ org.apache.catalina.startup.bootstrap.main(bootstrap.java:414) caused by: org.springframework.beans.factory.beancreationexception: error creating bean name 'entitymanagerfactory' defined in url [file:/c:/users/asus/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/stage/web-inf/classes/applicationcontext.xml]: invocation of init method failed; nested exception java.lang.illegalargumentexception: no persistence unit name 'persistance_unit' found @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1455) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:519) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:456) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:294) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:225) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:291) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:193) @ org.springframework.orm.jpa.support.persistenceannotationbeanpostprocessor.finddefaultentitymanagerfactory(persistenceannotationbeanpostprocessor.java:530) @ org.springframework.orm.jpa.support.persistenceannotationbeanpostprocessor.findentitymanagerfactory(persistenceannotationbeanpostprocessor.java:496) @ org.springframework.orm.jpa.support.persistenceannotationbeanpostprocessor$persistenceelement.resolveentitymanager(persistenceannotationbeanpostprocessor.java:657) @ org.springframework.orm.jpa.support.persistenceannotationbeanpostprocessor$persistenceelement.getresourcetoinject(persistenceannotationbeanpostprocessor.java:630) @ org.springframework.beans.factory.annotation.injectionmetadata$injectedelement.inject(injectionmetadata.java:150) @ org.springframework.beans.factory.annotation.injectionmetadata.inject(injectionmetadata.java:87) @ org.springframework.orm.jpa.support.persistenceannotationbeanpostprocessor.postprocesspropertyvalues(persistenceannotationbeanpostprocessor.java:339) ... 28 more caused by: java.lang.illegalargumentexception: no persistence unit name 'persistance_unit' found @ org.springframework.orm.jpa.persistenceunit.defaultpersistenceunitmanager.obtainpersistenceunitinfo(defaultpersistenceunitmanager.java:535) @ org.springframework.orm.jpa.localcontainerentitymanagerfactorybean.determinepersistenceunitinfo(localcontainerentitymanagerfactorybean.java:287) @ org.springframework.orm.jpa.localcontainerentitymanagerfactorybean.createnativeentitymanagerfactory(localcontainerentitymanagerfactorybean.java:239) @ org.springframework.orm.jpa.abstractentitymanagerfactorybean.afterpropertiesset(abstractentitymanagerfactorybean.java:310) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.invokeinitmethods(abstractautowirecapablebeanfactory.java:1514) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1452) ... 41 more 19 août 2015 16:16:16 org.apache.catalina.core.standardcontext start grave: error listenerstart 19 août 2015 16:16:16 org.apache.catalina.core.standardcontext start grave: erreur de démarrage du contexte [/jaba] suite aux erreurs précédentes 19 août 2015 16:16:16 org.apache.catalina.core.applicationcontext log info: closing spring root webapplicationcontext 19 août 2015 16:16:16 org.apache.catalina.loader.webappclassloader clearreferencesjdbc grave: web application [/jaba] registered jdbc driver [com.mysql.jdbc.driver] failed unregister when web application stopped. prevent memory leak, jdbc driver has been forcibly unregistered. 19 août 2015 16:16:17 org.apache.coyote.http11.http11protocol start info: démarrage de coyote http/1.1 sur http-8080 19 août 2015 16:16:17 org.apache.jk.common.channelsocket init info: jk: ajp13 listening on /0.0.0.0:8009 19 août 2015 16:16:17 org.apache.jk.server.jkmain start info: jk running id=0 time=0/19 config=null 19 août 2015 16:16:17 org.apache.catalina.startup.catalina start info: server startup in 4104 ms
one cause spring incompatibility java version. spring 3.2.0 doesnt work java 8. solution: upgrade 3.2.16 or above
Comments
Post a Comment