SSH框架搭建时出现的一些异常,记录备查

1.在搭建struts2工程时,出现如下异常:
严重: Exception starting filter struts2
Unable to load configuration. - bean - jar:file:/D:/Tomcat%206.0/webapps/tutorial/WEB-INF/lib/struts2-core-2.1.6.jar!/struts-default.xml:46:178

解决办法:[color=blue]在类库中添加commons-fileupload-1.2.1.jar即可[/color]。

2.在struts2搭建完以后,往struts2中引入spring时,web.xml中的配置如下:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param>

<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>

但项目启动时仍出现如下错误提示:
严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

解决办法:[color=blue]在类库中添加spring-web.jar即可[/color]。开始一直以为ContextLoaderListener是在spring-core.jar或spring-context.jar中,其实不是。

3.在struts中,由action跳转到action,可按如下配置:
<action name="Login" class="com.gyj.tutorial.LoginAction">
<result name="success" type="chain">GetBook</result>
<result name="error">/error.jsp</result>
</action>

<action name="GetBook"
class="com.gyj.tutorial.GetBooksAction">
<result name="success">/showBook.jsp</result>
<result name="login">/login.jsp</result>
</action>


4.在spring集成hibernate3时,在applicationContext.xml中配置sessionFactory
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>hibernate.cfg.xml</value>
</property>
</bean>


启动工程,出现如下错误:
[color=red]严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [org.springframework.orm.hibernate3.LocalSessionFactoryBean] for bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: problem with class file or dependent class; nested exception is java.lang.NoClassDefFoundError: org/springframework/dao/support/PersistenceExceptionTranslator
Caused by: java.lang.NoClassDefFoundError: org/springframework/dao/support/PersistenceExceptionTranslator[/color]
由“Caused by: java.lang.NoClassDefFoundError: org/springframework/dao/support/PersistenceExceptionTranslator”推断可能是缺少spring-dao.jar包。
在工程WEB-INF/lib目录中导入spring-dao.jar包,问题解决。

5.配置sessionFactory时,在指定属性configLocation的值时,
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>hibernate.cfg.xml</value>
</property>
</bean>

启动时,提示找不到文件:Caused by: java.io.FileNotFoundException: ServletContext resource [/hibernate.cfg.xml] cannot be resolved to URL because it does not exist
打开工程中的.classpath文件,其中src目录是配置在classpath中的(<classpathentry kind="src" path="src"/>),所以将文件hibernate.cfg.xml放在src目录中,然后将以上的配置修改为:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>

重新启动工程,问题解决。


6.在struts.xml中配置<constant name="struts.objectFactory" value="spring" />,让Spring管理struts的action,启动项目时出现错误:
Cannot locate the chosen ObjectFactory implementation: spring - [unknown location]
解决办法:在项目lib中加入包struts2-spring-plugin-2.1.6.jar,即可。

未完待续~
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值