2014-05-17 4 views
12

봄과 최대 절전 응용 프로그램을하고 있습니다. Tomcat 서버에서 응용 프로그램을 실행할 때 몇 가지 예외가 발생합니다.org.springframework.beans.factory.BeanCreationException : 'MyController'라는 이름의 빈을 생성하는 중 오류가 발생했습니다 :

INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'appServlet': initialization started 
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Refreshing WebApplicationContext for namespace 'appServlet-servlet': startup date [Sat May 17 19:51:03 CEST 2014]; parent: Root WebApplicationContext 
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml] 
INFO : org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring 
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/inscription],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.gestEtu.project.controller.CompteController.hello(java.lang.String,java.lang.String,java.lang.String,org.springframework.ui.Model) 
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.gestEtu.project.controller.HomeController.home(java.util.Locale,org.springframework.ui.Model) 
INFO : org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0' 
ERROR: org.springframework.web.servlet.DispatcherServlet - Context initialization failed 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'compteController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.gestEtu.project.model.service.CompteServiceImp com.gestEtu.project.controller.CompteController.compteServ; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'compteServiceImp': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void com.gestEtu.project.model.service.CompteServiceImp.setCompteDAO(com.gestEtu.project.model.dao.CompteDAOHib); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'compteDAOHib' defined in file [C:\Users\zouhair\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\TESTER\WEB-INF\classes\com\gestEtu\project\model\dao\CompteDAOHib.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.gestEtu.project.model.dao.CompteDAOHib]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.gestEtu.project.model.dao.CompteDAOHib.<init>() 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) 
    at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658) 
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:624) 
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:672) 
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:543) 
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484) 
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) 
    at javax.servlet.GenericServlet.init(GenericServlet.java:160) 
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1189) 
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1103) 
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1010) 
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4935) 
    at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5262) 
    at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5257) 
    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.gestEtu.project.model.service.CompteServiceImp com.gestEtu.project.controller.CompteController.compteServ; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'compteServiceImp': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void com.gestEtu.project.model.service.CompteServiceImp.setCompteDAO(com.gestEtu.project.model.dao.CompteDAOHib); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'compteDAOHib' defined in file [C:\Users\zouhair\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\TESTER\WEB-INF\classes\com\gestEtu\project\model\dao\CompteDAOHib.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.gestEtu.project.model.dao.CompteDAOHib]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.gestEtu.project.model.dao.CompteDAOHib.<init>() 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:508) 
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289) 
    ... 27 more 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'compteServiceImp': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void com.gestEtu.project.model.service.CompteServiceImp.setCompteDAO(com.gestEtu.project.model.dao.CompteDAOHib); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'compteDAOHib' defined in file [C:\Users\zouhair\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\TESTER\WEB-INF\classes\com\gestEtu\project\model\dao\CompteDAOHib.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.gestEtu.project.model.dao.CompteDAOHib]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.gestEtu.project.model.dao.CompteDAOHib.<init>() 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1017) 
    at org.springframework.be 

루트-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:p="http://www.springframework.org/schema/p" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> 

    <!-- Root Context: defines shared resources visible to all other web components --> 

    <bean id="propertyConfigurer" 
     class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" 
     p:location="/WEB-INF/jdbc.properties" /> 

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" 
     destroy-method="close" p:driverClassName="${jdbc.driverClassName}" 
     p:url="${jdbc.url}" p:username="${jdbc.username}" p:password="${jdbc.password}" /> 

    <!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) --> 
    <bean id="sessionFactory" 
     class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> 
     <property name="dataSource" ref="dataSource" /> 
     <property name="mappingResources"> 
      <list> 
       <value>com/gestEtu/project/model/bo/Utilisateur.hbm.xml</value> 
       <value>com/gestEtu/project/model/bo/Compte.hbm.xml</value> 
       <value>com/gestEtu/project/model/bo/Message.hbm.xml</value> 
       <value>com/gestEtu/project/model/bo/Groupe.hbm.xml</value> 
       <value>com/gestEtu/project/model/bo/Etudiant.hbm.xml</value> 
       <value>com/gestEtu/project/model/bo/Fichelecture.hbm.xml</value> 
       <value>com/gestEtu/project/model/bo/Document.hbm.xml</value> 
       <value>com/gestEtu/project/model/bo/Commentaire.hbm.xml</value> 

      </list> 
     </property> 

     <property name="hibernateProperties"> 
      <props> 
       <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> 
       <prop key="hibernate.show_sql">true</prop> 
       <prop key="hibernate.hbm2ddl.auto">update</prop> 
      </props> 
     </property> 
    </bean> 

    <!-- Transaction Manager --> 
    <bean id="txManager" 
     class="org.springframework.orm.hibernate4.HibernateTransactionManager"> 
     <property name="sessionFactory" ref="sessionFactory" /> 
    </bean> 
</beans> 

서블릿-context.xml에

<?xml version="1.0" encoding="UTF-8"?> 
<beans:beans xmlns="http://www.springframework.org/schema/mvc" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:beans="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd 
     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.xsd"> 

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure --> 

    <!-- Enables the Spring MVC @Controller programming model --> 
    <annotation-driven /> 

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory --> 
    <resources mapping="/resources/**" location="/resources/" /> 

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory --> 
    <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <beans:property name="prefix" value="/WEB-INF/views/" /> 
     <beans:property name="suffix" value=".jsp" /> 
    </beans:bean> 

    <context:component-scan base-package="com.gestEtu.project" /> 

</beans:beans> 

CompteController.java

package com.gestEtu.project.model.service; 

import java.util.List; 

import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.transaction.annotation.Transactional; 

import org.springframework.stereotype.Service; 

import com.gestEtu.project.model.bo.Compte; 
import com.gestEtu.project.model.bo.Utilisateur; 
import com.gestEtu.project.model.dao.CompteDAOHib; 

@Service 
@Transactional(readOnly = true) 
public class CompteServiceImp implements CompteService { 

    private CompteDAOHib compteDAO; 


    @Autowired 
    public void setCompteDAO(CompteDAOHib compteDAO) { 
     this.compteDAO = compteDAO; 
    } 

    @Override 
    public void ajouterCompte(Compte compte) { 
     compteDAO.ajouterCompte(compte); 
    } 

    @Override 
    public List<Compte> getComptes() { 
     return compteDAO.getComptes(); 
    } 

    @Override 
    public Compte findCompteByLogin(String login) { 

     return compteDAO.findCompteByLogin(login); 
    } 

    @Override 
    public void ajouterUtilisateur(Compte compte, Utilisateur utilisateur) { 
     this.ajouterCompte(compte); 

    } 

    @Override 
    public Utilisateur getUtilisateurById(int id) { 
     return null; 
    } 

    @Override 
    public List<Utilisateur> getUtilisateurs() { 
     return null; 
    } 

} 

는 누구의 도움이 문제를 해결하기 위해 할 수있는

compteService?

CompteDAOHib

package com.gestEtu.project.model.dao; 

import java.util.List; 

import org.hibernate.SessionFactory; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.orm.hibernate3.support.HibernateDaoSupport; 
import org.springframework.stereotype.Repository; 
import org.springframework.transaction.annotation.Propagation; 
import org.springframework.transaction.annotation.Transactional; 

import com.gestEtu.project.model.bo.Compte; 

@Repository 
@Transactional(propagation=Propagation.REQUIRED) 
public class CompteDAOHib extends HibernateDaoSupport implements CompteDAO { 


    public CompteDAOHib(SessionFactory sessionFactory) { 
     setSessionFactory(sessionFactory); 
    } 

    @Override 
    public void ajouterCompte(Compte compte) { 
     getHibernateTemplate().saveOrUpdate(compte); 
    } 

    @Override 
    public List<Compte> getComptes() { 
     try{ 
      return (List<Compte>) getHibernateTemplate().find("from compte") 
       .iterator(); 
     }catch (Exception e) { 
      return null; 
     } 
    } 

    @Override 
    public Compte findCompteByLogin(String login) { 
     if ((login == null) || (login == "")) { 
      return null; 
     } else 
      try { 
       return (Compte) getHibernateTemplate() 
         .find("from Compte c where c.login = ?", login) 
         .iterator().next(); 
      } catch (Exception e) { 
       return null; 
      } 
    } 

} 

CompteService 코드

package com.gestEtu.project.model.service; 

import java.util.List; 

import com.gestEtu.project.model.bo.Compte; 
import com.gestEtu.project.model.bo.Utilisateur; 


public interface CompteService { 

    public void ajouterCompte(Compte compte); 

    public List<Compte> getComptes(); 

    public Compte findCompteByLogin(String login); 

    public List<Utilisateur> getUtilisateurs(); 

    public Utilisateur getUtilisateurById(int id); 

    public void ajouterUtilisateur(Compte compte, Utilisateur utilisateur); 

} 

답변

8

:

BeanInstantiationException : 콩 클래스를 인스턴스화 할 수 없습니다 [com.gestEtu.project.model.dao.CompteDAOHib] : 없음 기본 생성자를 찾을 수 없음; 중첩 예외는 java.lang.NoSuchMethodException : com.gestEtu.project.model.dao.CompteDAOHib입니다. < 초기화하기 >() 기본적으로

, 봄은 기본 (인수 없음) 생성자를 호출하여 빈을 인스턴스화하려고합니다. 귀하의 경우 문제는 CompteDAOHib의 구현에 SessionFactory 인수가있는 생성자가 있다는 것입니다. @Autowired 주석을 생성자에 추가하면 Spring은 일치하는 유형의 bean 인 bean을 찾은 다음 생성자 인수로 제공합니다 (예 : SessionFactory).

@Autowired 
public CompteDAOHib(SessionFactory sessionFactory) { 
    // ... 
} 
2

예외는 분명히 문제가 있음을 나타냅니다. 여러분의 빈을 인스턴스화하는 봄

CompteDAOHib: No default constructor found

, 당신은 클래스 CompteDAOHib에 대한 빈 생성자를 제공해야합니다.

+0

내가 전에 생성자를 언급했다 –

1

@Controller에서 @Service를 CompteController로 변경하고 을 CompteDAOHib에 @Service 주석을 추가하십시오. 이 문제가 계속되면 알려주세요. 스택 트레이스에서 복사

+0

주석을 적용했지만 예외가 발생했습니다. org.springframework.beans.factory.BeanCreationException : 'compteController'라는 이름의 빈을 만드는 중에 오류가 발생했습니다 : 자동 종속 종속의 삽입이 실패했습니다. 중첩 예외는 org.springframework.beans.factory.BeanCreationException : 필드를 autowire 수 없습니다 : 개인 com.gestEtu.project.model.service.CompteService com.gestEtu.project.controller.CompteController.compteServ; 중첩 예외는 –

+0

당신은 지금 어떤 expections 있어요. – geddamsatish

+0

compteService 코드 – geddamsatish

1

org.springframework.beans.factory.BeanCreationException : 이름을 가진 bean을 생성 오류 'MyController에'

당신이 당신의 라이브러리에 ojdbc14.jar를 추가했는지 확인하십시오.

여기서 oracle11g을 사용하고 있는데,이 경우 ojdbc14.jar이 없습니다. 내가 무엇을 할 수 있을지?

4

비슷한 오류가 발생하여 공유하고 싶습니다. 어쩌면 그것은 누군가를 도울 것입니다.

당신이 EntityManager를 얻을 수 EntityManagerFactory를 사용하려는 경우, 당신이 사용하는지 확인하십시오

<persistence-unit name="name" transaction-type="RESOURCE_LOCAL"> 

하지 : persistance.xml

청소에

<persistence-unit name="name" transaction-type="JPA"> 

을하고 프로젝트를 다시 빌드, 도움이 될 것입니다.

관련 문제