SSH三大框架整合后的配置文件详解

学习三大框架Struts2 、 Hibernate 、 Spring时,涉及到三大框架的配置文件以及整合。今天就来详细写写三大框架配置文件的详细内容。

一 Spring的applicationContext.xml中的配置


xmlversion="1.0"encoding="UTF-8"?>

<beansxmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

xmlns:p="http://www.springframework.org/schema/p"

xsi:schemaLocation="http://www.springframework.org/schema/beans 

      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

      http://www.springframework.org/schema/context

           http://www.springframework.org/schema/context/spring-context-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/tx

           http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">


<context:component-scanbase-package="com.leipengzj"/>

<aop:aspectj-autoproxy/>


<beanid="dateSource"class="com.mchange.v2.c3p0.ComboPooledDateSource"destroy-method="close">

<propertyname="driverClass"value="com.mysql.jdbc.Driver">property>

<propertyname="jdbcUrl"value="jdbc:mysql:/3306/leiepngzj_table">property>

<propertyname="user"value="root">property>

<propertyname="password"value="root">property>

bean>

<beanid="sessionFactory"class="org.springframework.orm.hibernate3.annotation">

<propertyname="dateSource"ref="dateSource">property>

<propertyname="congifLocation"value="classpath:hibernate.cfg.xml">property>

bean>

<beanid="transactionManager"class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 

<propertyname="sessionFactory"ref="sessionFactory">property>

bean>

<tx:annotation-driventransaction-manager="transactionManager"/>

beans>


二 Hibernate.cfg.xml配置:

  

xmlversion='1.0'encoding='UTF-8'?>

DOCTYPEhibernate-configuration PUBLIC

          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"

          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">


<hibernate-configuration>


    <session-factory>

   

       <propertyname="dialect">org.hibernate.dialect.MySQLDialectproperty>

       

        <propertyname="show_sql">trueproperty>

       <propertyname="hbm2ddl.auto">updateproperty>

       

        <mappingresource="../../.hbm.xml"/>

        <mappingresource="../../.hbm.xml"/>

        <mappingresource="../../.hbm.xml"/>

        

    session-factory>


hibernate-configuration>


三 struts.xml中的配置文件:


xmlversion="1.0"encoding="UTF-8"?>

DOCTYPE strutsPUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN""http://struts.apache.org/dtds/struts-2.1.dtd">

<struts>

<constantname="struts.devMode"value="true">constant>

    

<constantname="struts.action.extension"value="action">constant>

<constantname="struts.configuration.xml.reload"value="true">constant>

<packagename="LunTanSystem"extends="struts-default">

<global-results>

<resultname="error">/error.jspresult>

<resultname="ajax">/ajax.jspresult>

<resultname="noLogin">/login.jspresult>

global-results>

<actionname="test"class="testAction">

<resultname="success">/test.jspresult>

action>

package>


struts>    


四 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">

  <display-name>display-name>

 

    <filter>

  <filter-name>struts2filter-name>

  <filter-class>

  org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

  filter-class>

  filter>

  <filter-mapping>

  <filter-name>struts2filter-name>

  <url-pattern>/*url-pattern>

  filter-mapping>


  

  <listener>

  <listener-class>org.springframework.web.context.ContextLoaderlistener-class>

  listener>

  <context-param>

  <param-name>contextConfigLocationparam-name>

  <param-value>classpath:applicationContext*.xmlparam-value>

  context-param>

  

  <welcome-file-list>

    <welcome-file>index.jspwelcome-file>

  welcome-file-list>

web-app>



你可能感兴趣的:(SSH三大框架整合后的配置文件详解)