MyEclipse 配置SSH (Struts2.1 Spring3.1 Hibernate4.1)

问题描述

在MyEclipse中,配置JSP开发用的SSH架构。


运行环境:

MyEclipse10.6    Struts2.1    Spring3.1    Hibernate4.1    JDK6


解决方案:

1.打开,新建一个Web Project项目。

MyEclipse 新建Web Project项目


2.在包视图中,右击项目,添加SSH库

首先添加Struts2.1库,过程依次如下图。

配置Struct2.1 Step1配置Struct2.1 Step2

点击完成后,继续右击选择配置Spring3.1,过程如下图。

配置Spring3.1 Step1

配置Spring3.1 Step2

同样点击完成,接着继续右击配置 ,其过程如下图所列。

配置Hibernate4.1 Step1

配置Hibernate4.1 Step2

配置Hibernate4.1 Step3

配置Hibernate4.1 Step4

配置Hibernate4.1 Step5

点击完成。


3.修改web.xml文件

打开项目中的web.xml(WebRoot/WEB-INF/web.xml),添加以下内容到该文件(添加在标签web-app内部)中,并保存。

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:/applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
   </listener>	
添加后的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">
  <display-name></display-name>
   <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:/applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
   </listener>	
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <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>*.action</url-pattern>
  </filter-mapping></web-app>


4.部署项目到服务器并运行。


可能问题:

P1.

Line: 220 - com/opensymphony/xwork2/spring/SpringObjectFactory.java:220:-1

Caused by: java.lang.NullPointerException

S1.

出现这个问题,可能是没有把Spring的监听添加到web.xml文件中。若如此,需执行解放方案中的步骤4后再尝试。


P2.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/context/CurrentSessionContext

Caused by: java.lang.NoClassDefFoundError: org/hibernate/context/CurrentSessionContext

Caused by: java.lang.ClassNotFoundException: org.hibernate.context.CurrentSessionContext

S2.

这个问题,Spring3.1以后的版本比较支持Hibernate4.x,而在使用Spring3.0以及其以前版本时,会出现。

因此需升级Spring的版本,或者修改配置文件中Spring与Hibernate的相关的类名。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值