整合ssh框架的配置文件

ssh整合
一.applicationContext.xml
        1配置數據源
            <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
                    <property name="location" value="classpath:db.properties"></property>
            </bean>
            <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
                    <property name="driverClassName" value="${driver}"/>
                    <property name="url" value="${url}"/>
                    <property name="username" value="${username}"/>
                    <property name="password" value="${password}"/>
            </bean>
        2.配置hibernate的sessionFactory工廠
            <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
                    <property name="dataSource" ref="dataSource"/>//引用數據源
                    <property name="hibernateProperties">
                        <props>
                            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>//配置相關數據庫庫的方言(爲了檢查hql翻譯sql語句的語法)
                            <prop key="hibernate.show_sql">false</prop>//是否顯示sql語句
                            <prop key="hibernate.format_sql">false</prop>//格式化sql語句
                        </props>
                    </property>
                    <!-- 直接配置註解的實體類(不用再編寫配置xxx.hbm.xml文件)-->
                    <property name="annotatedClasses">
                        <list>
                            <value>cn.sxt.vo.ceshi.Module</value>
                            <value>cn.sxt.vo.ceshi.Suite</value>
                        </list>
                    </property>
            </bean>
        3.配置事務管理器(此管理器是hibernate提供的,其實spring也有事務管理器)
            <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
                    <property name="sessionFactory" ref="sessionFactory"/>
            </bean>
        4.配置事務監聽器
            <tx:advice id="txAdvice" transaction-manager="txManager">
                    <tx:attributes>
                        <tx:method name="*" propagation="REQUIRED"/>//監聽所有的方法
                    </tx:attributes>
            </tx:advice>
        5.配置事務提交的切入點
            <aop:config>
                    <aop:pointcut expression="execution(* cn.sxt.service..*.*(..))" id="pointcut"/>//切入點
                    <aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut"/>//引用事務監聽器
            </aop:config>
        6.配置註解掃描器
            <context:component-scan base-package="cn.sxt"/>//掃描sxt包的所有類裏面的註解
二.strut.xml
    添加相應的映射文件就可以了
        例如:<struts>
                   <package name="yxl" extends="struts-default"></package>
                   <include file="config/yxl/struts/ceshi.xml"></include>
                   <include file="config/yxl/struts/suite.xml"></include>
                   <include file="config/yxl/struts/module.xml"></include>
             </struts>
三.web.xml
    1.配置spring容器相關的資源文件和創建容器的監聽類
        <!--定位spring配置文件-->
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:applicationContext.xml</param-value>
        </context-param>
        <!--web容器啓動時就會觸發此監聽器調用相應的方法創建spring容器-->
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>//
        </listener>
    2.配置session的關閉的一個過濾器
      <filter>
        <filter-name>osiv</filter-name>
        <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
      </filter>
      <filter-mapping>
        <filter-name>osiv</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    2.配置struts的核心過濾器
       <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>*.action</url-pattern>
      </filter-mapping>
    
   
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章