托马斯是正确的,但我相信,通过创建对象实例“新”不脚与Spring的概念:
我认为你需要做的是这样:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
<value>com.vanilla.objects.Student</value>
<value>com.vanilla.objects.Address</value>
</list>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
,然后你可以用它在Spring bean中:
@Autowired
SessionFactory sessionFactory;
,然后里面的方法:
Session session = sessionFactory.getCurrentSession();
这对我有效,但我很困惑,需要放置bean的位置。对于其他人,如果你有一个包含'@Configuration'注解的类,我会把'@Bean'方法放在那里。加载没有问题,我很好去。 –
AbstractSessionFactoryBean已弃用 – Blauhirn