我有以下标准配置:
<bean id="globalSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"></ref>
</property>
<property name="mappingResources">
<list>
<value>...</value>
</list>
</property>
</bean>
在另一个模块中:
<bean id="configurationSettingsService" class="com.HibernateConfigurationSettingsService">
<property name="sessionFactory" ref="globalSessionFactory"/>
</bean>
使用会话工厂的类:
public class HibernateConfigurationSettingsService implements ConfigurationSettingsService {
private HibernateTemplate hibernateTemplate;
private SessionFactory sessionFactory;
public SessionFactory getSessionFactory() {
return sessionFactory;
}
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
this.hibernateTemplate = new HibernateTemplate(sessionFactory);
}
只有类路径上的库版本是:
hibernate 3.5.4-Final spring 3.2.3.RELEASE
尝试在 Tomee 中运行应用程序(使用 tomcat 7),得到以下错误:
Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of ty
pe 'org.springframework.orm.hibernate3.LocalSessionFactoryBean' to required type 'org.hibernate.SessionFactory' for property 'sessionFactory'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.springframework.orm.hibernate3.LocalSessionFactoryBean] to required type [org.hibernate.S
essionFactory] for property 'sessionFactory': no matching editors or conversion strategy found
任何人都知道为什么 Spring 不在这里重新调整 SessionFactory 的实例?
谢谢大家。
解决!问题在于在两个类路径上拥有 spring 库,一旦我将单个模块依赖项设置为提供,一切都很好。