您的位置:首页 > 其它

整合ssh框架的配置文件

2016-11-04 21:47 357 查看
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>

    

   
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: