之前讲的内容已经或多或少和整合挂上钩了,当然,之前的内容就不过多的重复。现在在把这个钩真正的挂上。废话不多说。GO!
struts.xml的配置:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<!-- 把Struts2交给Spring管理 -->
<constant name="struts.objectFactory" value="spring"></constant>//必须的
<package name="xxx" extends="struts-default" namespace="">
<action name="LoginAc" class="bean的id">//这里的class不是全路径,只是Spring的Bean组件而已了。例如有个Bean的id为adminLogin,则class="adminLogin"。
<result name="success">/index.jsp</result>
</action>
</package>
</struts>
applicationContext.xml的配置:
<?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" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<context:component-scan base-package="com.lrl"></context:component-scan>
<!--数据源的定义-->//数据源需commons-pool.jar、commons-dbcp.jar
<bean id="bbsDateSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver">
</property>
<property name="url" value="jdbc:mysql://localhost:3306/bbspro">
</property>
<property name="username" value="root"></property>
<property name="password" value="123"></property>
</bean>
<!--sessionFactory的定义-->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="bbsDateSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="packagesToScan">
<value>com.bbs.entity</value>//这里写Entity的包路径,也就是实体类的包路径
</property>
</bean>
<bean id="testDao" class="com.junit.test.TestDao">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
</beans>
之前用的是Annotation的Entity,代码如上,下面的代码可以配置使用xxx.hbm.xml的SessionFactory。
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="mySqlDateSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/lrl/entity/User.hbm.xml</value>//这里是xml
</list>
</property>
</bean>
web.xml的配置:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
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_2_5.xsd">
<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>/*</url-pattern>
</filter-mapping>
<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>
//字符编码
<filter>
<filter-name>encoding</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
基本配置就如此而已。如果用MyEclipse开发。把JavaEE5.0的jar拷出,导入lib里。避免部分冲突。详情本博客的其他文章。。
总结:
(1)主要开发过程:applicationContext.xml+struts.xml+web.xml
(2)spring管理Hibernate,那么hibernate.cfg.xml就不需要了,在applicationContext配置数据源等信息即可
分享到:
相关推荐
ssh框架整合配置文件 ssh框架整合配置文件 ssh框架整合配置文件 ssh框架整合配置文件 ssh框架整合配置文件 ssh框架整合配置文件 ssh框架整合配置文件 ssh框架整合配置文件 ssh框架整合配置文件 ssh框架整合配置文件 ...
SSH2整合jar包和步骤,以及配置文件的关键代码
ssh dwr 整合配置ssh dwr 整合配置ssh dwr 整合配置
SSH 整合原代码 包括2种方式:注解&xml;配置 (已测试, 原创) 包含所需的lib
ssh整合时的配置ssh整合时的配置(经典详细)
ssh整合的一些配置文件
ssh;整合流程;xml配置文件;Struts2
myEclipse8.5配置整合SSH步骤
ssh2最新整合配置
SSH整合笔记和配置文件,
该项目为ssh框架整合,Myeclipse下开发,其中包含jar包,配置文件
ssh框架整合maven+ssh配置文件,包括hibernate详细配置,struts2的详细配置,spring的整合配置
SSH三大框架整合 struts2(使用xml配置)+hibernate(使用xml配置)+spring(使用xml配置),实现分页查询,其他增删该查的接口已经写好。
JavaWeb中的Jar包整合,并配置了Struts的配置文件,hibernate的配置文件,Spring的配置文件。(配置文件是空的,但是有配置文件的头)
ssh框架整合jar包,ssh框架所需基本jar包都在里面,不包含配置文件。
本篇文章主要介绍了SSH框架和Redis的整合,详细的介绍了Struts+Spring+Hibernate和Redis整合,有兴趣的可以了解一下。
SSH框架整合,全jpa注解真正的零配置。 struts2.3.8 spring3.2 hibernate4.1.9. 带有分页,全局异常,权限拦截器,session过滤等功能。 内有jar包。导入开发工具后部署既可跑起来。已做了简单的数据库操作功能。供...
集成SSH框架的系统从职责上分为四层:表示层、业务逻辑层、数据持久层和域模块层,以帮助开发人员在短期内搭建结构清晰、可复用性好、维护方便的Web应用程序。其中使用Struts作为系统的整体基础架构,负责MVC的分离...
欢迎下载SSH2项目整合.zip 此zip资源包含: 1.SSH2的初始配置文件; 2.SSH2的整合包(SSH2+JSON); 3.SSH2整合后的参考项目(不含包,请自行拷贝)
jBPM4.4+ssh 整合配置及完整实例