Wildfly Spring + Hibernate SessionFactory NoSuchMethodError

时间:2015-11-29 21:03:29

标签: spring hibernate wildfly nosuchmethoderror sessionfactory

这是我的配置:

  • 应用服务器: jsboss Wildfly 9.X - > (它有hibernate模块,版本:4)

  • Legacy spring application:spring version:2.0.6 hibernate 3.2.6.ga

我必须开发一个Rest服务来调用一些dao函数。

在代码段代码中,我的遗留app-context.xml有一些关键语句:

<bean id="groupDao" class="my.package.dao.UserDaoHibernate">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

<bean id="sessionFactory" parent="sessionFactoryTemplate"/>

<bean id="sessionFactoryTemplate" abstract="true"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="mappingResources">
        <list>
            <value>User.hbm.xml</value>             
        </list>
    </property>
    <property name="configurationClass"
        value="my.package.hibernate.Configuration" />       
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
            <prop key="hibernate.show_sql">false</prop>
            <prop key="hibernate.generate_statistics">false</prop>
            <prop key="hibernate.use_sql_comments">false</prop>
            <prop key="hibernate.default_batch_fetch_size">64</prop>
            <prop key="hibernate.max_fetch_depth">1</prop>
            <prop key="hibernate.connection.release_mode">after_transaction</prop>
            <prop key="hibernate.connection.provider_class">my.package.connection.MyDBHibernateConnectionProvider</prop>
        </props>
    </property> 
</bean>

这是我的UserDaoHibernate类:

public class UserDaoHibernate extends org.springframework.orm.hibernate3.support.HibernateDaoSupport implements UserDao
{   
    @SuppressWarnings("unchecked")
    public User findByUsername(String username, boolean allowProfileUser)
    {
        List<User> users = getHibernateTemplate().findByNamedQueryAndNamedParam(
            "User.findByUsername", "user", username);
        ...
        return user;
    }

为了避免api冲突,我添加了一个部署描述符:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
    <deployment>
        <exclusions>
            <module name="org.hibernate" /> 
        </exclusions>
    </deployment>
</jboss-deployment-structure>

当我运行代码时,我发现了这个异常:

Caused by: org.glassfish.jersey.server.ContainerException: java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session;
    at org.glassfish.jersey.servlet.internal.ResponseWriter.rethrow(ResponseWriter.java:256)
    at org.glassfish.jersey.servlet.internal.ResponseWriter.failure(ResponseWriter.java:238)
    at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:486)
    at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:317)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
    at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:292)
    at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1139)
    at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:460)

在调试模式下输入代码并检查UserDao中的sessionFactory我看到它的类型是:

org.hibernate.internal.SessionFactoryImpl

这是一个Hibernate4实现。内部包不包含在Hibernate 3核心中。所以WildFly在某种程度上重叠了它的hibernate实现。

我做错了什么?

0 个答案:

没有答案