懶人專用SSH框架下的基本配置

    項目結束,馬上就要出去找工作了,這段時間也不用寫項目,就整理了一些以後可能會用的到的配置,還有一個原因就是我不想去記憶。。。。。。。。。

    SSH下application.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:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop"
     xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    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/tx
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    ">


    <!-- 事務 -->
    <bean id="txManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <!-- 鏈接點 -->
    <tx:advice id="txAvice" transaction-manager="txManager">
        <tx:attributes>
            <tx:method name="find*" propagation="NOT_SUPPORTED"
                read-only="false" />
            <tx:method name="query*" propagation="NOT_SUPPORTED"
                read-only="false" />
            <tx:method name="save*" propagation="REQUIRED" />
            <tx:method name="add*" propagation="REQUIRED" />
            <tx:method name="delete*" propagation="REQUIRED" />
            <tx:method name="update*" propagation="REQUIRED" />
            <tx:method name="remove*" propagation="REQUIRED" />
            <tx:method name="keep*" propagation="REQUIRED" />
        </tx:attributes>
    </tx:advice>
    <!-- AOP切面 -->
    <aop:config>
        <aop:pointcut
            expression="execution(* com.hpsvse.xyz.qqzone.dao.impl.*.*(..))"
            id="myPoint" />
        <aop:advisor advice-ref="txAvice" pointcut-ref="myPoint" />
    </aop:config>

    
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver">
        </property>
        <property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl">
        </property>
        <property name="username" value="QQZone"></property>
        <property name="password" value="qqzone"></property>
    </bean>
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource">
            <ref bean="dataSource" />
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">
                    org.hibernate.dialect.Oracle9Dialect
                </prop>
            </props>
        </property>
        <property name="mappingResources">
            <list>
            <!-- xml映射實體 -->
                <value>
                    com/hpsvse/xyz/qqzone/entity/Friendmsg.hbm.xml
                </value>
                <value>
                    com/hpsvse/xyz/qqzone/entity/Logact.hbm.xml
                </value>
                <value>
                    com/hpsvse/xyz/qqzone/entity/Users.hbm.xml
                </value>
                <value>
                    com/hpsvse/xyz/qqzone/entity/Message.hbm.xml
                </value>
                <value>
                    com/hpsvse/xyz/qqzone/entity/Marks.hbm.xml
                </value>
                <value>
                    com/hpsvse/xyz/qqzone/entity/Activitys.hbm.xml
                </value>
                <value>com/hpsvse/xyz/qqzone/entity/Dic.hbm.xml</value>
                <value>com/hpsvse/xyz/qqzone/entity/Say.hbm.xml</value>
                <value>
                    com/hpsvse/xyz/qqzone/entity/Fridends.hbm.xml
                </value>
                <value>
                    com/hpsvse/xyz/qqzone/entity/Album.hbm.xml
                </value>
                <value>
                    com/hpsvse/xyz/qqzone/entity/Photo.hbm.xml
                </value>
                <value>
                    com/hpsvse/xyz/qqzone/entity/Comments.hbm.xml
                </value>
                <value>
                    com/hpsvse/xyz/qqzone/entity/Pwdprotect.hbm.xml
                </value>
            </list>
        </property>
    </bean>
    <!-- 開啓註解 -->
    <context:annotation-config></context:annotation-config>
    <context:component-scan base-package="com.hpsvse.xyz.qqzone.*"></context:component-scan>
</beans>

        SSH下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>login.jsp</welcome-file>
  </welcome-file-list>
  
  <!-- opensessionview -->
      <servlet>
        <servlet-name>ImageAction</servlet-name>
        <servlet-class>com.hpsvse.xyz.qqzone.web.action.ImageAction</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>ImageAction</servlet-name>
        <url-pattern>/ImageAction</url-pattern>
    </servlet-mapping>
  <filter>
        <filter-name>opensessionview</filter-name>
        <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>opensessionview</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    
    <!-- struts過濾器 -->
  <filter>
      <filter-name>strutsFilter</filter-name>
      <filter-class>
          org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
      </filter-class>
  </filter>
  <filter-mapping>
      <filter-name>strutsFilter</filter-name>
      <url-pattern>/*</url-pattern>
  </filter-mapping>
  
  <!-- 加載applicationContext.xml -->
  <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext*.xml</param-value>
    </context-param>
    
    <!-- 加載監聽 -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
  </web-app>






發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章