Code Bye

SSH整合连接ORACLE,BeanCreationException

 

struts没问题,主要是加上spring和Hibernate就出错,提示sessionFactory没创建成功,配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" 
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" 
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 
http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 

  
<!-- 数据库连接 --> 

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" 
destroy-method="close"> 
	<property name="driverClassName"><value>oracle.jdbc.driver.OracleDriver</value> </property>  
	<property name="url"><value>jdbc:oracle:thin:@127.0.0.1:1521:orcl</value> </property> 
	<property name="username"> <value>myuser</value></property>
	<property name="password"> 	<value>myuser</value> </property> 
</bean> 
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> 
<!-- 数据库连接 --> 
<property name="dataSource">
	<ref local="dataSource"/>
</property>
<!-- hibernate自身属性 --> 
<property name="hibernateProperties"> 
	<props> 
		<prop key="hibernate.show_sql">true</prop> 
		<prop key="hibernate.format_sql">true</prop> 
		<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop> 
		<!-- 解决no session found --> 
		<prop key="hibernate.current_session_context_class">thread</prop>
	</props> 
</property> 
<property name="annotatedClasses"> 
	<list> 
		<value>com.myssh.model.Userinfo</value> 
	</list> 
</property> 
</bean> 

<!-- 用户Dao --> 

<bean id="userDao" class="com.myssh.daoimpl.UserinfoDAOImpl" scope="singleton">
	<property name="sessionFactory"> 
		<ref local="sessionFactory"/> 
	</property> 
</bean> 

<!-- 用户Service --> 
<bean id="userService" class="com.myssh.serviceimpl.UserinfoServiceImpl" scope="singleton"> 
	<property name="userDao"> 
		<ref local="userDao"/> 
	</property> 
</bean> 

<!-- 用户Action -->
<bean id="saveUserAction" class="com.myssh.controller.MyInsert" scope="prototype">
	<property name="userService"> 
		<ref local="userService"/> 
	</property> 
</bean> 
  

</beans> 


错误信息如下:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name “”sessionFactory”” defined in ServletContext resource [/WEB-INF/classes/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/apache/commons/collections/CursorableLinkedList


8分
缺少 commons-collections-3.2.jar ,下载个添加进去再起试试看
我是用的hibernate4.1.9,里面没有这个包呀,我看hibernate3.6里面才有这个包,刚刚我加了commons-collections-3.1.jar 进去之后,还是不行

8分
去官网看看 http://commons.apache.org/proper/commons-collections/download_collections.cgi 我的网速有点低,这个一直没打开
你打开下载下高版本的Commons jar包,试试看

8分
很明显缺jar包啊。缺少apache的 commons-collections 的jar包。

楼主去spring或者hibernate的压缩包里翻一翻,找个版本高的放进去基本就可以了。一般都有的,如果没有,就去apache的官网下载一个。


8分
如果hibernate里面没有,那就一定是在spring里面,找一找。一般都有的。

8分
新添加的jar包,要放在项目路径里面,并且,项目要重新部署才能生效。楼主核实一下哈。
我用了commons-collections3.2.1还是同样的报错!
我是用myeclipse启动tomcat的时候就报错了
如果我把tomcat中webapps中这个项目部署文件里的lib全部删除,然后再重新启动tomcat,在启动tomcat的时候就会报错,如下:
严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
我的WEB.XML配置如下:
<?xml version="1.0" encoding="UTF-8"?>

<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> 

<welcome-file-list> 
	<welcome-file>index.jsp</welcome-file> 
</welcome-file-list> 

<!-- struts2拦截器 --> 
<filter> 
<filter-name>struts2</filter-name> 
	<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> 
</filter> 

<filter-mapping> 
	<filter-name>struts2</filter-name> 
	<url-pattern>/*</url-pattern> 
</filter-mapping>

 <!-- 创建spring工厂监听器  -->
<listener> 
	<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 

 <!-- 告知spring context config location 的存储位置   -->
<context-param> 
	<param-name>contextConfigLocation</param-name> 
	<param-value>/WEB-INF/classes/applicationContext.xml</param-value> 
</context-param> 


</web-app> 

不知道会不会是web.xml配置有问题,但是里面就这么几行呀。


5分
应该不是配置文件的问题,就是缺少jar包的问题。
你把jar包都删了,当然什么都缺了。

commons-collections.jar 
commons-collections-3.2.jar
commons-dbcp-1.2.2.jar
commons-pool.jar

这几个jar包,你缺哪一个?

commons-collections.jar 
 commons-collections-3.2.jar不是一样的吗?

5分
看看你的项目添加完包之后有没有编译成功

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明SSH整合连接ORACLE,BeanCreationException