我不知道这个设置有什么问题......
AVERTISSEMENT:
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userDao': Unsatisfied dependency expressed through method 'anyMethodName' parameter 0: Error creating bean with name 'sessionFactory' defined in class path resource [hbn-config.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.jboss.logging.Logger.debugf(Ljava/lang/String;I)V; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [hbn-config.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.jboss.logging.Logger.debugf(Ljava/lang/String;I)V
juil. 03, 2016 6:56:50 PM org.springframework.cache.ehcache.EhCacheManagerFactoryBean destroy
INFOS: Shutting down EhCache CacheManager
juil. 03, 2016 6:56:50 PM org.springframework.web.context.ContextLoader initWebApplicationContext
GRAVE: Context initialization failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userDao': Unsatisfied dependency expressed through method 'anyMethodName' parameter 0: Error creating bean with name 'sessionFactory' defined in class path resource [hbn-config.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.jboss.logging.Logger.debugf(Ljava/lang/String;I)V; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [hbn-config.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.jboss.logging.Logger.debugf(Ljava/lang/String;I)V
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:651)
UserDao:
@Repository
public class UserDao extends AbstractDao<User> {
private static Logger LOG = LoggerFactory.getLogger(UserDao.class);
public UserDao() {
}
public List<User> findAllUsers() {
Query q = getHibernateTemplate()
.getSessionFactory()
.openSession()
.createQuery("from " + entityClass.getSimpleName());
List<User> list = q.list();
return list;
}
AbstractDao:
public abstract class AbstractDao<E> extends CustomHibernateDaoSupport {
protected final Class<E> entityClass;
@SuppressWarnings("unchecked")
public AbstractDao() {
entityClass = (Class<E>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
}
protected HibernateTemplate getOneResultTemplate() {
HibernateTemplate oneResultTemplate = createHibernateTemplate(getSessionFactory());
oneResultTemplate.setMaxResults(1);
return oneResultTemplate;
}
protected Query createQuery(String queryString) {
return getSessionFactory().getCurrentSession().createQuery(queryString);
}
@Transactional(readOnly = false)
public void save(E entity) {
getHibernateTemplate().save(entity);
}
@Transactional(readOnly = false)
public void saveOrUpdate(E entity) {
getHibernateTemplate().saveOrUpdate(entity);
}
@Transactional(readOnly = false)
public void update(E entity) {
getHibernateTemplate().update(entity);
}
@Transactional(readOnly = false)
public void delete(E entity) {
getHibernateTemplate().delete(entity);
}
@SuppressWarnings("unchecked")
public List<E> list() {
Query q = getHibernateTemplate().getSessionFactory().openSession()
.createQuery("from " + entityClass.getSimpleName());
return q.list();
}
CustomHibernateDaoSupport:
public abstract class CustomHibernateDaoSupport extends HibernateDaoSupport {
@Autowired
public void anyMethodName(SessionFactory sessionFactory) {
setSessionFactory(sessionFactory);
}
}
webappContext:
<?xml version="1.0" encoding="UTF-8"?>...
<cache:annotation-driven />
<context:property-placeholder location="classpath:app.properties" />
<!-- Auto scan the components -->
<context:annotation-config />
<context:component-scan base-package="com.example" />
<bean id="applicationContextHolder"
class="com.example.myproject.core.util.ApplicationContextHolder" />
<import resource="classpath:hbn-config.xml" />
<import resource="classpath:cache-config.xml" />
hbn-config:
<?xml version="1.0" encoding="UTF-8"?>...
<!-- Hibernate session factory -->
<tx:annotation-driven />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<!-- Hibernate session factory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.max_fetch_depth">${hibernate.max_fetch_depth}</prop>
<prop key="hibernate.jdbc.fetch_size">${hibernate.jdbc.fetch_size}</prop>
<prop key="hibernate.jdbc.batch_size">${hibernate.jdbc.batch_size}</prop>
<prop key="hibernate.temp.use_jdbc_metadata_defaults">${hibernate.temp.use_jdbc_metadata_defaults}</prop>
<prop key="hibernate.order_inserts">${hibernate.order_inserts}</prop>
<prop key="hibernate.order_updates">${hibernate.order_updates}</prop>
</props>
</property>
<property name="packagesToScan" value="com.example.myproject.core.model" />
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<aop:config>
<aop:pointcut id="serviceMethods"
expression="execution(*com.example.myproject.core.dao.*Dao.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethods" />
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED" read-only="false" />
<!-- <tx:method name="save*" propagation="REQUIRED" read-only="false"
/> -->
<!-- <tx:method name="add*" propagation="REQUIRED" read-only="false" /> -->
<!-- <tx:method name="update*" propagation="REQUIRED" read-only="false"
/> -->
<!-- <tx:method name="delete*" propagation="REQUIRED" read-only="false"
/> -->
<!-- <tx:method name="export*" propagation="REQUIRED" read-only="false"
/> -->
<!-- <tx:method name="import*" propagation="REQUIRED" read-only="false"
/> -->
</tx:attributes>
</tx:advice>
</beans>
答案 0 :(得分:0)
类路径中的jboss-logging版本与Hibernate所期望的版本不同。