ssh配置详解

    技术2022-05-11  34

    一.首先配置web.xml

    <!--加入spring 配置-->

    <context-param>    <param-name>contextConfigLocation</param-name>    <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> <listener>    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>

    <!-- 利用spring监听 编码设置--> <filter>     <filter-name>Spring character encoding filter</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>Spring character encoding filter</filter-name>     <url-pattern>/*</url-pattern> </filter-mapping>

    <!-- 配上openSessionInViewFilter ( 作用hibernate加载问题,可解决session close..)-->

    <filter>      <filter-name>hibernateFilter</filter-name>      <filter-class>       org.springframework.orm.hibernate3.support.OpenSessionInViewFilter      </filter-class> </filter>

    <filter-mapping>      <filter-name>hibernateFilter</filter-name>      <url-pattern>*.do</url-pattern> </filter-mapping>

    <!--加入struts的配置-->

    <servlet>     <servlet-name>action</servlet-name>     <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>     <init-param>       <param-name>config</param-name>       <param-value>/WEB-INF/struts-config.xml</param-value>     </init-param>     <init-param>       <param-name>debug</param-name>       <param-value>3</param-value>     </init-param>     <init-param>       <param-name>detail</param-name>       <param-value>3</param-value>     </init-param>     <load-on-startup>0</load-on-startup> </servlet> <servlet-mapping>     <servlet-name>action</servlet-name>     <url-pattern>*.do</url-pattern> </servlet-mapping>

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

    二在struts中配置

    <!--加入Spring代理-->

    <message-resources parameter="com.lch.struts.ApplicationResources" /> <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"> <set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml"/> </plug-in>

    <!--在action中代理-->

    type="org.springframework.web.struts.DelegatingActionProxy">

    三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:tx=" http://www.springframework.org/schema/tx "     xmlns:aop=" http://www.springframework.org/schema/aop " xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop        http://www.springframework.org/schema/aop/spring-aop-2.5.xsd " default-lazy-init="true"> <bean id="dataSource"    class="org.apache.commons.dbcp.BasicDataSource">    <property name="driverClassName"     value="com.mysql.jdbc.Driver">    </property>    <property name="url"     value="jdbc:mysql://localhost:3306/china">    </property>    <property name="username" value="root"></property>    <property name="password" value="root"></property> </bean> <bean id="sessionFactory"    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">    <property name="dataSource"     ref="dataSource" >    </property>    <property name="hibernateProperties">     <props>      <prop key="hibernate.dialect">       org.hibernate.dialect.MySQLDialect      </prop>      <prop key="hibernate.show_sql">true</prop>     </props>    </property>    <property name="mappingResources">     <list>      <value>com/lch/bbs/dao/Message.hbm.xml</value>      <value>com/lch/bbs/dao/Replay.hbm.xml</value>      <value>com/lch/bbs/dao/User.hbm.xml</value>      </list>    </property>

    <!--再加入事务管理-->

    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">    <property name="sessionFactory">      <ref bean="sessionFactory"/>    </property> </bean> <bean id="transactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true">    <property name="transactionManager">         <ref bean="transactionManager"/>      </property>    <property name="transactionAttributes">      <props>        <prop key="save*">PROPAGATION_REQUIRED,-LogicException</prop>        <prop key="delete*">PROPAGATION_REQUIRED,-LogicException</prop>        <prop key="update*">PROPAGATION_REQUIRED,-LogicException</prop>        <prop key="find*">PROPAGATION_REQUIRED,-LogicException</prop>        <prop key="get*">PROPAGATION_REQUIRED,-LogicException</prop>        <prop key="list*">PROPAGATION_REQUIRED,-LogicException,readOnly</prop>      </props>    </property> </bean> <bean id="logAdvice" class="com.example.exception.LogExceptionAdvice"/> <bean id="autoAppendLogAdvice" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">       <property name="beanNames">

    <!--配置id=*ManagerTarget-->         <list><value>*ManagerTarget</value></list>       </property>       <property name="interceptorNames">

    <!--logAdvice就是上面的ID class="com.example.exception.LogExceptionAdvice"-->         <value>logAdvice</value>       </property>     </bean>

    <bean id="usersDao" class="com.example.gw.users.UsersDao">       <property name="sessionFactory">         <ref bean="sessionFactory"/>       </property>     </bean>

    <bean id="usersManagerTarget" class="com.example.gw.users.UsersManager">       <property name="usersDao">         <ref bean="usersDao"/>       </property>     </bean> </bean>

    转自http://blog.csdn.net/kaikai19871010/archive/2009/08/21/4469322.aspx


    最新回复(0)