You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring4迁移至Spring5时出现LocalSessionFactoryBean类找不到异常

解决Spring 5迁移至JBoss 7.1时的ClassNotFoundException问题

问题原因

Spring 5.x版本已完全移除org.springframework.orm.hibernate4包下的所有类,该版本仅支持Hibernate 5及以上版本。你在spring-context.xml中仍引用org.springframework.orm.hibernate4.LocalSessionFactoryBean,但当前依赖的Spring 5.3.20中不存在这个类,因此启动时抛出ClassNotFoundException。

解决方案

1. 替换配置类

将spring-context.xml中的配置项:

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <!-- 原有配置内容 -->
</bean>

替换为Hibernate 5对应的类:

<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
    <!-- 原有配置内容 -->
</bean>

2. 确认依赖完整性

确保Maven的pom.xml中引入与Spring核心版本匹配的spring-orm依赖(版本需统一为5.3.20):

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-orm</artifactId>
    <version>5.3.20</version>
</dependency>

3. 处理JBoss容器类加载冲突

JBoss 7.1自带旧版本Hibernate模块,可能与项目中的Hibernate 5.3.28.Final产生类加载冲突。在项目WEB-INF目录下创建jboss-deployment-structure.xml文件,排除容器自带的Hibernate相关模块:

<jboss-deployment-structure>
    <deployment>
        <exclusions>
            <module name="org.hibernate" />
            <module name="org.hibernate.annotations.common" />
            <module name="org.hibernate.jpa" />
        </exclusions>
    </deployment>
</jboss-deployment-structure>

内容的提问来源于stack exchange,提问作者user26270

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 16:36:20