67,513
社区成员
发帖
与我相关
我的任务
分享
<bean class="com.crf.core.web.listener.DictionaryCacheListener">
</bean>
package com.crf.core.web.listener;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import com.crf.model.TestModel;
import com.crf.service.TestService;
public class DictionaryCacheListener implements ApplicationContextAware {
@Override
public void setApplicationContext(ApplicationContext arg0)
throws BeansException {
TestService testService = (TestService)arg0.getBean("testService");
System.out.println("-----------------启动时执行此方法1111111------------------------");
TestModel testModel = testService.getTestModel(1);
System.out.println(testModel.getName());
}
}
@Resource(name="sessionFactory")
private SessionFactory sessionFactory;
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
public SessionFactory getSessionFactory() {
return sessionFactory;
}
public Session getSession() {
return sessionFactory.getCurrentSession();
}
Caused by: org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread
at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:134)
at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1014)
at com.crf.base.BaseDao.getSession(BaseDao.java:51)
at com.crf.base.BaseDao.load(BaseDao.java:82)
at com.crf.service.TestService.getTestModel(TestService.java:41)
at com.crf.core.web.listener.DictionaryCacheListener.setApplicationContext(DictionaryCacheListener.java:49)
at org.springframework.context.support.ApplicationContextAwareProcessor.invokeAwareInterfaces(ApplicationContextAwareProcessor.java:119)
at org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:94)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:408)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
org.hibernate.HibernateException: load is not valid without active transaction