0

Tomcatを起動しようとしていますが、起動しようとすると次のエラーが発生します

SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'countriesDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void com.fexco.helloworld.web.util.CustomHibernateDaoSupport.anyMethodName(org.hibernate.SessionFactory); nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.hibernate.SessionFactory] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}

国Dao

package com.fexco.helloworld.web.dao;

import com.fexco.helloworld.web.model.Countries;

public interface CountriesDao {


void save(Countries countries);
void update(Countries countries);
void delete(Countries countries);
Countries findByCountry(String country);
}

CountriesDaoImpl の開始

package com.fexco.helloworld.web.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.fexco.helloworld.web.model.Countries;
import com.fexco.helloworld.web.util.CustomHibernateDaoSupport;

@Repository("countriesDao")
public class CountriesDaoImpl extends CustomHibernateDaoSupport implements CountriesDao{

public void save(Countries countries){
    getHibernateTemplate().save(countries);
}
......
}

Application-config.xml の一部

<bean id="countriesDao" class="com.fexco.helloworld.web.dao.CountriesDaoImpl">
    <property name="sessionFactory" ref="sessionFactory"/>
</bean>
.... 
<context:annotation-config />
<context:component-scan base-package="com.fexco.helloworld.web" />

<bean 
  class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>

CustomHibernateDaoSupport クラス

package com.fexco.helloworld.web.util;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public abstract class CustomHibernateDaoSupport extends HibernateDaoSupport
{    
@Autowired
public void anyMethodName(SessionFactory sessionFactory)
{
    setSessionFactory(sessionFactory);
}
}

CountriesDaoImpl が実際に CountriesDao を実装していないため、エラーですか? このエラーを解決する方法を知っている人はいますか?

ありがとう

4

1 に答える 1

0

dao実装クラスでセッションファクトリが定義されていないようです。まだ定義されていない場合は1つを定義し、両方の構成を使用しないようにする必要があります。

            @Autowired
        @Qualifier("sessionFactory")
        public void seSessionFactory(SessionFactory sessionFactory) {

            this.setSessionFactory(sessionFactory);
        }
于 2012-04-13T14:47:59.013 に答える