Struts2.0+Hiberbate3.2+Spring3.2整合

Eclipse上整合SSH步骤

I.导入Struts2 所需的jar包   

freemarker-2.3.8.jar                     支持freemarker(struts2的UI标签的模板使用FreeMarker编写)的,在webwork中也有

ognl-2.6.11.jar                            支持ognl语言(对象图导航语言(Object Graph Navigation  Language))的,struts2框架通过其读写对象的属性,webwork也支持ognl语言

xwork-2.0.4.jar   work的核心jar包,由于struts2是webwork的升级版本,所以必定对其有所依赖(struts2在其基础上构建)

struts-core-1.3.5.jar                    Struts的核心包

struts2-spring-plugin-2.0.11.jar   struts2与spring集成时使用的,引入该jar包后需要在struts.xml中指定struts的ObjectFactory(可以是struts也可以是spring),不然程序会报错 

commons-logging-1.0.4.jar          日志记录

commons-fileupload-1.x.x.jar   commons项目中的关于文件上传的包, struts2.1.6版本后必须加入此文件

2.导入Hibernate3所需的jar包

hibernate3.jar                 核心包

antlr-2.7.6.jar                Hibernate中HQL跟SQL相互转换的支持

commons-collections-2.1.1.jar  集合类的工具

commons-logging-1.0.4.jar      日志记录(Struts中也有,SSH整合中随意导入哪个都可以)

dom4j-1.6.1.jar                对dom4j的封装,是解析xml文件的

javassist.jar                  字节码解释器

jta.jar                         Hibernate对事务的处理

asm.jar

asm-attrs.jar

cglib-2.1.3.jar                 (如果使用此包,责必须导入asm.jar跟asm-attrs.jar包,反之则不需要)

ehcache-1.2.3.jar               如果没有其它缓存,这个缓存是需要的(有责不需要)

3.导入Spring3所需的jar包

spring-beans-3.2.4.RELEASE.jar     springIoC(依赖注入)的基础实现,所有应用都要用到的,它包含访问配置文件、创建和 管理bean以及进行Inversion of Control / Dependency Injection(IoC/DI)操作相关的所有类

spring-context-3.2.4.RELEASE.jar   Spring 提供在基础 IoC 功能上的扩展服务,此外还提供许多企业级服务的支持,如 邮件 服务、任务调度、JNDI定位、EJB 集成、远程访问、 缓存以及各种视图层框架的封装等

spring-context-support-3.2.4.RELEASE.jar   spring-context 的扩展支持,包含支持缓存Cache(ehcache)、JCA、JMX、邮 件服务(Java Mail、COS Mail)、任务计划Scheduling(Timer、Quartz)方面的类

spring-core-3.2.4.RELEASE.jar     Spring框架的核心工具包

spring-expression-3.2.4.RELEASE.jar    Spring表达式语言

spring-jdbc-3.2.4.RELEASE.jar        Spring对JDBC的封装

spring-orm-3.2.4.RELEASE.jar      提供对Hibernate、MyBatis开源框架的支持,包含Spring对DAO特性集进行了扩展

spring-oxm-3.2.4.RELEASE.jar  spring 对Object/XMI 的映射的支持,可以让JAVA与XML之间来回切换     

spring-struts-3.2.4.RELEASE.jar   提供对集成Struts的支持

spring-tx-3.2.4.RELEASE.jar   为JDBC、Hibernate、JDO、JPA等提供的一致的声明式和编程式事务管理。

spring-web-3.2.4.RELEASE.jar       包含Web应用开发时,用到Spring框架时所需的核心类,包括自动载入WebApplicationContext 特性的类、Struts与JSF集成类、文件上传的支持类、Filter类和大量工具辅助类

spring-aop-3.2.4.RELEASE.jar    提供AOP(面向切面编程)实现,如果没用到Aop可以不需要

导入以上的包之后还需要导入,以下的几个jar包

slf4j.api-1.6.1.jar(

一个日志系统的服务的api,SLF4J是一个用于日志系统的简单Facade,允许最终用户在部署其应用时使用其所希望的日志系统

),slf4j-nop-1.6.1.jar(对slf4j.api-1.6.1.jar的支持),hibernate-annotations-3.2.0.ga.jar,hibernate-commons-annotations-3.2.0.Final.jar,ejb3-persistence.jar,mysql-connector-java-5.1.26-bin.jar(数据库驱动包)

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

接着是配置文件的编写

(1.)web.xml文件的配置如下

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<!-- 设置监听程序,使得应用程序一启动就开始创建我们的Beans -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- 配置应用程序加载的路劲 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<!-- struts基本配置,主要是负责过滤url请求的  -->
<display-name>ssh_1</display-name>
<filter>
<filter-name>Struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>Struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

(2.)applicationContext.xml文件配置如下(我的配置文件都放在了/WEB-INF下)

<?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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-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.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/yan"></property>
<property name="username" value="zou"></property>
<property name="password" value="123456"></property>
</bean>


<!-- Hibernate配置 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="HibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="show_sql">show</prop>
<prop key="hibernate.jdbc.batch_size">50</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>ssh/cfg/xml/User.hbm.xml</value>(此处是项目文件的路径)
</list>
</property>
</bean>
</beans>

到此配置结束,Struts.xml的配置就没贴出来了

然后启动Tomcat服务器,http://localhost:8888/ssh看到默认的index.jsp界面的内容。



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值