2014-10-17 4 views
0

이 질문은 Spring + Hibernate + Maven org.hibernate.MappingException: AnnotationConfiguration instance is required의 진화입니다.봄 + 최대 절전 모드 + 메이븐 NoSuchBeanDefinitionException

log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment). 
log4j:WARN Please initialize the log4j system properly. 
Exception in thread "main" org.springframework.beans.factory.BeanCreationException:  Error creating bean with name 'client' defined in class path resource [config.xml]: Cannot resolve reference to bean 'ClientDAOx' while setting bean property 'clientDAO'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'ClientDAOx' is defined 
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:336) 
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1456) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197) 
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:302) 
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298) 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) 
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.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) 
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) 
at ee.st.running.aktorstask.Main.main(Main.java:17) 
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'ClientDAOx' is defined 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:641) 
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1157) 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:280) 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) 
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328) 
... 15 more 

다음과 같은 설정 파일은 다음과 같습니다 :

내 현재 로그입니다

<?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" 
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" 
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" 
xmlns:task="http://www.springframework.org/schema/task" 
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd" 
default-autowire="byName"> 

    <context:component-scan base-package=".*" /> 

<tx:annotation-driven/> 

    <context:annotation-config /> 

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> 
    <property name="driverClassName" value="com.mysql.jdbc.Driver" /> 
    <property name="url" value="jdbc:mysql://localhost:3306/sqlconnection" /> 
    <property name="username" value="admin" /> 
    <property name="password" value="root" /> 
    </bean> 


    <bean id="sessionFactory"  class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> 
     <property name="dataSource" ref="dataSource"></property> 
    <property name="annotatedClasses"> 
      <list> 
        <value>ee.st.running.model.Client</value> 
        <value>ee.st.running.model.Order</value>     
      </list> 
     </property> 

    <property name="hibernateProperties"> 
     <props> 
     <prop 
     key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop> 
     <prop key="hibernate.show_sql">true</prop> 
     </props> 

    </property> 
    </bean> 

    <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager" 
    p:sessionFactory-ref="sessionFactory"> 
    </bean> 

    <bean id = "client" class = "ee.st.running.model.Client"> 
    <property name="clientDAO" ref = "ClientDAO"></property> 
    </bean> 

    <bean id = "clientDAO" class = "ee.st.running.dao.ClientDAOImpl"> 
    <property name="sessionFactory" ref = "sessionFactory"></property> 
    </bean> 


    <bean id = "order" class = "ee.st.running.model.Order"> 
    <property name="orderDAO" ref = "OrderDAO"></property> 
    </bean> 

     <bean id = "orderDAO" class = "ee.st.running.dao.OrderDAOImpl"> 
    <property name="sessionFactory" ref = "sessionFactory"></property> 
    </bean> 

    </beans> 

이 문제는 DAO 빈을 만드는 항상 것으로 보인다. 그것은 내 config.xml에 default-autowire = "byName"을 추가 한 후에 발생합니다.

Error creating bean with name 'clientDAOImpl' defined in file [C:\Users\Странник\workspace\aktorstask\target\classes\ee\st\running\dao\ClientDAOImpl.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required 

답변

0

귀하의 콩 ID가 clientDAO이며 ClientDAO으로 심판을주고있다 : 아직 이전에 다른 오류가 발생했습니다. 그것은

<bean id = "client" class = "ee.st.running.model.Client"> 
    <property name="clientDAO" ref = "ClientDAO"></property> //Here is the problem. 
    </bean> 
변경 후

<bean id = "client" class = "ee.st.running.model.Client"> 
    <property name="clientDAO" ref = "ClientDAO"></property> //Here is the problem. 
    </bean> 

    <bean id = "clientDAO" class = "ee.st.running.dao.ClientDAOImpl"> 
    <property name="sessionFactory" ref = "sessionFactory"></property> 
    </bean> 

대소되어야

관련 문제