我是在Spring 管理HIbernate 的设置过程中
新生成的DAO文件,在修改了
ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
SessionFactory sessionFactory=(SessionFactory) ctx.getBean("sessionFactory");
后
@Transactional
@Service("MassageHome")
public class MassageHome {
private static final Log log = LogFactory.getLog(MassageHome.class);
ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
SessionFactory sessionFactory=(SessionFactory) ctx.getBean("sessionFactory");
/*private final SessionFactory sessionFactory = getSessionFactory();*/
protected SessionFactory getSessionFactory() {
try {
return (SessionFactory) new InitialContext().lookup("SessionFactory");
} catch (Exception e) {
log.error("Could not locate SessionFactory in JNDI", e);
没有加上 @Scope(“prototype”)
@Transactional
@Service("MassageHome")
@Scope("prototype")
public class MassageHome {
private static final Log log = LogFactory.getLog(MassageHome.class);
ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
SessionFactory sessionFactory=(SessionFactory) ctx.getBean("sessionFactory");
/*private final SessionFactory sessionFactory = getSessionFactory();*/
protected SessionFactory getSessionFactory() {
try {
return (SessionFactory) new InitialContext().lookup("SessionFactory");
} catch (Exception e) {
log.error("Could not locate SessionFactory in JNDI", e);