spring整合hibernate时遇到的ClassNotFound问题


遇到404错误的时候,打开console就可以看到遇到的问题了

1、ClassNotFoundException:org.springframework.jdbc.dataSource.DriverManagerDataSource

在这里插入图片描述
解决方法:

①检查有没有忘记加spring和jdbc有关的三个包:

在这里插入图片描述

②检查spring版本是否混合

③在百度这个问题的时候看到的:上服务器之后遇到的报错

问题描述:

本地都是好好的,为什么在服务器上就不行了,后来才知道服务器是无外网环境的,由于程序用了spring,在加载applicationContext.xml的时候会报上述错误。
主要的原因是在applicationContext.xml文件里要根据namespace找schemaLocation的地址,如果没有配置schemaLocation的话,就找namespace下的地址,由于未联网,所以会失败。

解决方法:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-4.1.xsd"
       default-lazy-init="false">

改为:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       classpath:/org/springframework/beans/factory/xml/spring-beans-4.1.xsd ">

2、ClassNotFoundException:org.springframework.orm.hibernate4.localSessionFactoryBean

在这里插入图片描述
解决方法:

①检查是否缺少spring-orm包

②检查spring版本是否低于3.1

spring3.1版本之后才加了对hibernate4的支持。如果用的是maven,那么pom.xml文件需要改一下:

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

题外话:关于maven:
pom作为项目对象模型。通过xml表示maven项目,使用pom.xml来实现。
主要描述了项目:包括配置文件;开发者需要遵循的规则,缺陷管理系统,组织和licenses,项目的url,项目的依赖性,以及其他所有的项目相关因素。
groupId 和artifactId,这两个结合起来,想一个坐标系一样,知道这两个就好像知道的了 坐标系中哪个点一样,就能知道你用的是哪个jar包了。

③如果你用的是spring5+hibernate4

虽然这个搭配非常的神奇…
但是原因是spring5的orm包下localSessionFactoryBean类的路径是orm.hibernate5.localSessionFactoryBean,而不是hibernate4.
因此需要更改applicationContext.xml:
将下面这个的hibernate4改为hibernate5.

<!-- 把数据源注入给session工厂 -->
		<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
			<property name="dataSource" ref="dataSource" />
			
			<!-- 配置映射文件 -->
			<property name="mappingResources">
				<list>
					<value>../../...hbm.xml</value>
				</list>
			</property>
		</bean> 

当然hibernate5和hibernate4当中有些类的路径是不一样的,所以这样改了之后这个问题是解决了,还是会有其他问题出现的,所以要么把spring版本改到4,要么把hibernate版本改到5.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值