【发布时间】:2014-10-08 07:43:40
【问题描述】:
我正在使用这个包 org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean 通过 xml 文件(applicationContext.xml)注入 sessionFactory。
是否可以为整个 Web 应用程序只设置一次 sessionFactory?我怎样才能做到这一点?
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan">
<list>
<value>com.mahesh</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
</props>
</property>
</bean>
【问题讨论】:
-
1.问题的标题和问题本身要求不同的东西。 2. 向我们展示 XML 中的 bean 定义(编辑您的问题以执行此操作!) 3. 为什么您认为 Spring 会为整个应用程序创建多个
SessionFactory? -
@AaronDigulla 我编辑了标题...
-
好吧,除非您为 sessionFactory bean 使用非默认范围(并且您应该不),否则 spring 将只为整个 wep 应用程序使用一个...跨度>
-
@AaronDigulla 我粘贴了包含 xml 代码 sn-p 的链接......我很困惑如何在我的所有 DaoImpl 类中访问会话......我正在使用 getHibernateTemplate 进行基本的 CRUD 操作。 .我错过了什么吗?
-
向我们展示您的 DaoImpl 类中的一些代码。
标签: spring spring-mvc