java - No such bean Definition and impossible to create bean -
java - No such bean Definition and impossible to create bean -
i'm developping web application containing 4 layers . utilize spring mvc jpa/hibernate frameworks. problem can't autowire field opmanimpl in creerbilanimpl class , no such bean definition exception . need help please!!
construirebilanimpl
@service public class construirebilanimpl implements construirebilan { @autowired(required=true) @qualifier("operationmanagerimpl") private operationmanager opmanimpl ; private float immobilisations_corporelles=sommecomptes(1266,1322); public construirebilanimpl(){}; public void setopmanimpl(operationmanagerimpl x){opmanimpl=x;} public float sommecomptes(int... doubles){ if (this.opmanimpl==null){system.out.println("baaaaaaaaaaaaaadddddddddd");} homecoming opmanimpl.sommecomptes(doubles); } public float getimmobilisations_corporelles(){return immobilisations_corporelles;} public void setimmobilisations_corporelles(float x){immobilisations_corporelles=x;} }
operationmanagerimpl
@repository public class operationmanagerimpl implements operationmanager { @persistencecontext(unitname="erp") private entitymanager em; public operationmanagerimpl(){}; public void setem(entitymanager emm){em=emm;} public void creeroperation(opération op) { if (em!=null){system.out.print(" manager de bean initialisé");} em.persist(op); system.out.println("dou5oul---------2");} public opération rechercheroperation(int clé){ opération oper=em.find(opération.class,clé); homecoming oper; } public void supprimeroperation(int clé) { opération oper=em.find(opération.class,clé); em.remove(oper); } public void modifierid(int clé,int nv){ opération oper=em.find(opération.class,clé); oper.setidop(nv); em.flush(); } public void modifierjournal(int clé,char j){ opération oper=em.find(opération.class,clé); oper.setjournal(j); em.flush(); } public void modifiercompte(int clé,int nvc){ opération oper=em.find(opération.class,clé); oper.setcompte(nvc); em.flush(); } public void modifierlibellé(int clé,string nvl ){ opération oper=em.find(opération.class,clé); oper.setlibellé(nvl); em.flush(); } public void modifierdate(int clé,date nvd){ opération oper=em.find(opération.class,clé); oper.setdateop(nvd); em.flush(); } public void modifierdr(int clé,float nvdr){ opération oper=em.find(opération.class,clé); oper.setdr(nvdr); em.flush(); } public void modifiercr(int clé,float nvcr){ opération oper=em.find(opération.class,clé); oper.setcr(nvcr); em.flush(); } public list<opération> listeopération() { string ss="select op opération op"; query req= em.createquery(ss); homecoming req.getresultlist(); } public void supprimeropération(int ref){ opération op=em.find(opération.class, ref); em.remove(op); } public float sommecomptes(int... doubles) { string liste= new string(); string x; (int d : doubles) { x=integer.tostring(d); x=x.concat(","); liste=liste.concat(x); } liste=liste.substring(0, liste.length()-1); string cc =" select sum(op.cr) opération op "; system.out.println(cc); query req= em.createquery(cc); number somme=(number)req.getsingleresult(); homecoming somme.floatvalue(); } }
stacktrace
juin 24, 2014 2:34:29 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 'operationcontroller': injection of autowired dependencies failed; nested exception org.springframework.beans.factory.beancreationexception: not autowire field: private com.ensi.erp.metier.construirebilan com.ensi.erp.controllers.operationcontroller.bil; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'construirebilanimpl' defined in file [c:\users\housseminfo\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\erp_pcd\web-inf\classes\com\ensi\erp\metier\construirebilanimpl.class]: instantiation of bean failed; nested exception org.springframework.beans.beaninstantiationexception: not instantiate bean class [com.ensi.erp.metier.construirebilanimpl]: constructor threw exception; nested exception java.lang.nullpointerexception @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor.postprocesspropertyvalues(autowiredannotationbeanpostprocessor.java:288) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.populatebean(abstractautowirecapablebeanfactory.java:1120) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:522) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:461) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:295) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:223) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:292) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:194) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:607) @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:932) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:479) @ org.springframework.web.context.contextloader.configureandrefreshwebapplicationcontext(contextloader.java:383) @ org.springframework.web.context.contextloader.initwebapplicationcontext(contextloader.java:283) @ org.springframework.web.context.contextloaderlistener.contextinitialized(contextloaderlistener.java:112) @ org.apache.catalina.core.standardcontext.listenerstart(standardcontext.java:4961) @ org.apache.catalina.core.standardcontext.startinternal(standardcontext.java:5455) @ org.apache.catalina.util.lifecyclebase.start(lifecyclebase.java:150) @ org.apache.catalina.core.containerbase$startchild.call(containerbase.java:1559) @ org.apache.catalina.core.containerbase$startchild.call(containerbase.java:1549) @ java.util.concurrent.futuretask$sync.innerrun(unknown source) @ java.util.concurrent.futuretask.run(unknown source) @ java.util.concurrent.threadpoolexecutor.runworker(unknown source) @ java.util.concurrent.threadpoolexecutor$worker.run(unknown source) @ java.lang.thread.run(unknown source) caused by: org.springframework.beans.factory.beancreationexception: not autowire field: private com.ensi.erp.metier.construirebilan com.ensi.erp.controllers.operationcontroller.bil; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'construirebilanimpl' defined in file [c:\users\housseminfo\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\erp_pcd\web-inf\classes\com\ensi\erp\metier\construirebilanimpl.class]: instantiation of bean failed; nested exception org.springframework.beans.beaninstantiationexception: not instantiate bean class [com.ensi.erp.metier.construirebilanimpl]: constructor threw exception; nested exception java.lang.nullpointerexception @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor$autowiredfieldelement.inject(autowiredannotationbeanpostprocessor.java:514) @ org.springframework.beans.factory.annotation.injectionmetadata.inject(injectionmetadata.java:87) @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor.postprocesspropertyvalues(autowiredannotationbeanpostprocessor.java:285) ... 23 more caused by: org.springframework.beans.factory.beancreationexception: error creating bean name 'construirebilanimpl' defined in file [c:\users\housseminfo\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\erp_pcd\web-inf\classes\com\ensi\erp\metier\construirebilanimpl.class]: instantiation of bean failed; nested exception org.springframework.beans.beaninstantiationexception: not instantiate bean class [com.ensi.erp.metier.construirebilanimpl]: constructor threw exception; nested exception java.lang.nullpointerexception @ org.springframework.beans.factory.support.constructorresolver.autowireconstructor(constructorresolver.java:288) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.autowireconstructor(abstractautowirecapablebeanfactory.java:1049) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbeaninstance(abstractautowirecapablebeanfactory.java:953) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:490) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:461) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:295) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:223) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:292) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:194) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.findautowirecandidates(defaultlistablebeanfactory.java:873) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.doresolvedependency(defaultlistablebeanfactory.java:815) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.resolvedependency(defaultlistablebeanfactory.java:730) @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor$autowiredfieldelement.inject(autowiredannotationbeanpostprocessor.java:486) ... 25 more caused by: org.springframework.beans.beaninstantiationexception: not instantiate bean class [com.ensi.erp.metier.construirebilanimpl]: constructor threw exception; nested exception java.lang.nullpointerexception @ org.springframework.beans.beanutils.instantiateclass(beanutils.java:163) @ org.springframework.beans.factory.support.simpleinstantiationstrategy.instantiate(simpleinstantiationstrategy.java:121) @ org.springframework.beans.factory.support.constructorresolver.autowireconstructor(constructorresolver.java:280) ... 37 more caused by: java.lang.nullpointerexception @ com.ensi.erp.metier.construirebilanimpl.sommecomptes(construirebilanimpl.java:67) @ com.ensi.erp.metier.construirebilanimpl.<init>(construirebilanimpl.java:22) @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) @ sun.reflect.nativeconstructoraccessorimpl.newinstance(unknown source) @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(unknown source) @ java.lang.reflect.constructor.newinstance(unknown source) @ org.springframework.beans.beanutils.instantiateclass(beanutils.java:148) ... 39 more
root-context.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:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" 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"> <!-- root context: defines shared resources visible other web components --> <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/dberp"></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="defaultdatasource" ref="datasource"></property> <property name="persistencexmllocations"> <list> <value>classpath*:meta-inf/persistence.xml</value> </list> </property> </bean> <bean id="entitymanagerfactory" class="org.springframework.orm.jpa.localcontainerentitymanagerfactorybean"> <property name="persistenceunitmanager" ref="persistenceunitmanager"></property> <property name="persistenceunitname" value="erp"></property> </bean> <bean id="transactionmanager" class="org.springframework.orm.jpa.jpatransactionmanager"> <property name="entitymanagerfactory" ref="entitymanagerfactory"></property> </bean> <bean name="operationmanager" class="com.ensi.erp.dao.operationmanagerimpl"/> <bean id="opser" class="com.ensi.erp.metier.gereroperationimpl"> <property name="opmanimpl" ref="operationmanager"></property> </bean> <!-- <bean name="opmanimpl2" class="com.ensi.erp.dao.operationmanagerimpl"/> <bean id="bilan" class="com.ensi.erp.metier.construirebilanimpl"> <property name="opmanimpl" ref="opmanimpl2"></property> </bean>--> <tx:annotation-driven transaction-manager="transactionmanager"/> <context:annotation-config/> <context:component-scan base-package="com.ensi"/> </beans>
you have not linked application-context.xml web.xml file.
this problem.
check if have entry in web.xml of spring configuration file
or:
you may have 2 config files, example:
spring-servlet.xml spring-security.xmlso beans defined in 1 not able find in other.
so should seek <import resource="spring-servlet.xml"/>
in spring-security.xml .
java spring hibernate jpa
Comments
Post a Comment