SSH整合时xml文件写法

来源:互联网 发布:淘宝网卖什么最赚钱 编辑:程序博客网 时间:2024/05/18 01:55

SSH整合时spring.xml和struts.xml两个文件中需要写的代码
这里只写几个文件中的代码 至于各个包中每个类的代码这里就不列出来了

首先是spring

<?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.xsd                        http://www.springframework.org/schema/context                        http://www.springframework.org/schema/context/spring-context.xsd                        http://www.springframework.org/schema/aop                        http://www.springframework.org/schema/aop/spring-aop.xsd                        http://www.springframework.org/schema/tx                         http://www.springframework.org/schema/tx/spring-tx.xsd"><!-- 组件扫描 --><context:component-scan base-package="cn.itcast.oa"></context:component-scan><!-- 找到外部配置jdbc文件 --><context:property-placeholder location="jdbc.properties"/><!-- 配置数据源 --><bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">    <property name="driverClass" value="${driverClass}"></property>    <property name="jdbcUrl" value="${jdbcUrl}"></property>    <property name="user" value="${user}"></property>    <property name="password" value="${password}"></property>    <property name="initialPoolSize" value="${initialPoolSize}"></property>    <property name="minPoolSize" value="${minPoolSize}"></property>    <property name="maxPoolSize" value="${maxPoolSize}"></property></bean><!-- 配置sessionfactory --><bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">    <!-- 引用datasource -->    <property name="dataSource" ref="dataSource" />    <!-- 注入hibernate属性 -->    <property name="hibernateProperties">        <props>            <!-- 方言 -->            <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>                <prop key="hibernate.hbm2ddl.auto">update</prop>                <!-- 显示sql -->                <prop key="hibernate.show_sql">true</prop>                <!-- 格式化sql -->                <prop key="hibernate.format_sql">true</prop>        </props>    </property>    <!-- hibernate映射文件路径 -->    <property name="mappingDirectoryLocations">        <list>            <value>classpath:cn/itcast/oa/domain</value>        </list>    </property></bean><!-- 配置事务 --><bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">    <property name="sessionFactory" ref="sessionFactory"></property></bean><!-- 提供对注解的支持 --><context:annotation-config /><!-- 注解驱动 --><tx:annotation-driven transaction-manager="txManager"/></beans>

接下来是struts的

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts PUBLIC    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"    "http://struts.apache.org/dtds/struts-2.3.dtd"><struts>    <!-- 开发者模式 -->    <constant name="struts.devMode" value="true" />    <!-- 对象工厂指定为spring -->    <constant name="struts.objectFactory" value="spring"/>    <!-- 设置访问后缀 -->    <package name="default" namespace="/" extends="struts-default">

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">    <!-- 通过上下文参数指定spring配置文件的位置 -->    <context-param>        <param-name>contextConfigLocation</param-name>        <param-value>classpath:beans.xml</param-value>    </context-param>    <!-- 配置spring的上下文载入器监听器 ,项目启动时加载spring -->    <listener>        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>    </listener>    <!-- 配置struts2的前端控制器 -->    <filter>        <filter-name>struts</filter-name>        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>    </filter>    <filter-mapping>        <filter-name>struts</filter-name>        <url-pattern>/*</url-pattern>    </filter-mapping>  <welcome-file-list>    <welcome-file>index.jsp</welcome-file>  </welcome-file-list></web-app>
原创粉丝点击