我正在開發包含4層的web應用程序。 我使用Spring MVC JPA/HIBERNATE框架。 問題是我不能自動裝入字段opmanimpl在creerBilanImpl類 並且我沒有得到這樣的bean定義異常。 我需要幫助!沒有這樣的bean定義和不可能創建bean
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");}
return 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é);
return 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 from opération op";
Query req= em.createQuery(ss);
return 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;
for (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) from opération op ";
System.out.println(cc);
Query req= em.createQuery(cc);
Number somme=(Number)req.getSingleResult();
return somme.floatValue();
}
}
堆棧跟蹤
juin 24, 2014 2:34:29 AM 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 with name 'operationController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.ensi.erp.metier.ConstruireBilan com.ensi.erp.controllers.OperationController.bil; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with 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 is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.ensi.erp.metier.ConstruireBilanImpl]: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1120)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:607)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4961)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5455)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.ensi.erp.metier.ConstruireBilan com.ensi.erp.controllers.OperationController.bil; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with 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 is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.ensi.erp.metier.ConstruireBilanImpl]: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:514)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)
... 23 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with 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 is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.ensi.erp.metier.ConstruireBilanImpl]: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:288)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1049)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:953)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:490)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:873)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:815)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:730)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:486)
... 25 more
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.ensi.erp.metier.ConstruireBilanImpl]: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:121)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:280)
... 37 more
Caused by: java.lang.NullPointerException
at com.ensi.erp.metier.ConstruireBilanImpl.sommeComptes(ConstruireBilanImpl.java:67)
at com.ensi.erp.metier.ConstruireBilanImpl.<init>(ConstruireBilanImpl.java:22)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148)
... 39 more
根的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 to all 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>
請發表您的'根context.xml'文件和web.xml'的'相關部分。 –
完成我發佈了root-context和web.xml文件 – housseminfo