私はHibernateでSpring 4を設定しようとしています。私は、Hibernateが動作するかどうかを確認するために、JUnitテストでアプリケーションを起動しています。名前 'usersDao'のBeanを作成するHibernate.ErrorでSpringを設定する: 'sessionFactory'フィールドで表現されている満足しない依存関係
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'offersDao': Injection of autowired dependencies failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/cache/spi/RegionFactory
が、私はそのアドレスにRegionFactoryを持っています: enter image description here
Error creating bean with name 'usersDao': Unsatisfied dependency expressed through field 'sessionFactory': Error creating bean with name 'sessionFactory' defined in class path resource [ConfigTest/datasource.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.hibernate.cfg.Configuration.<init>(Lorg/hibernate/boot/MetadataSources;)V; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [ConfigTest/datasource.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.hibernate.cfg.Configuration.<init>(Lorg/hibernate/boot/MetadataSources;)V
この
は私がエラーに直面休止状態4を使用する場合も、私のdatasource.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"
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">
<context:component-scan base-package="/WebMVCtest/test/Config">
</context:component-scan>
<beans profile="dev">
<context:property-placeholder
location="ConfigTest/jdbc.properties" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc.driver}"></property>
<property name="url" value="${jdbc.url}"></property>
<property name="password" value="${jdbc.password}"></property>
<property name="username" value="${jdbc.username}"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
</props>
</property>
<property name="packagesToScan">
<list>
<value>DAO</value>
</list>
</property>
</bean>
</beans>
</beans>
です
あらかじめご了承ください!
'usersDao' beanがどのように定義されているかを示すことができますか?それはXMLでもですか?あるいは、 'context:component-scan'で拾いましたか? –
DAOパッケージに入っています。これは 'packagesToScan'プロパティのために選択されます。ユーザーDao: '@Repository @Component(" usersDao ") public class UsersDao { private NamedParameterJdbcTemplate jdbc; @Autowired プライベートSessionFactory sessionFactory; @Autowired プライベートPasswordEncoder passwordエンコーダ; @Autowired公共ボイドsetDataSource(データソースJDBC){ this.jdbc =新しいNamedParameterJdbcTemplate(JDBC);};公共 @SuppressWarnings( "未チェック") 公開セッションのセッション(){ 戻りsessionFactory.getCurrentSession()}リスト getAllUsers(){ return session()。createQuery( "ユーザー")。リスト();} –