文章目录
遇到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.