SSM配置文件

applicationContext.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:context="http://www.springframework.org/schema/context"

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

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

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

xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd

http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd

http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd

http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd

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

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

<!-- 自动扫描该包,使SpringMVC认为包下用了@controller注解的类是控制器 --> 

<context:component-scan base-package="com.haiersoft.buztest.*"/> 

<!-- 默认的注解映射的支持 -->  

<mvc:annotation-driven/>

<!-- mybatis+事务

 -->

<import resource="spring-mybatis.xml"/>

<!-- 拦截器 -->

<import resource="spring-interceptors.xml"/>

</beans>

Spring-mybatis.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:jee="http://www.springframework.org/schema/jee"

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

xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:util="http://www.springframework.org/schema/util"

xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"

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

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

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

                     http://www.springframework.org/schema/context/spring-context.xsd

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

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

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

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

 

<context:annotation-config />

<!-- 启用AspectJ对Annotation的支持 -->         

    <aop:aspectj-autoproxy/> 

 

<!-- 引入配置文件 -->

<bean id="propertyConfigurer"

class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

<property name="location" value="classpath:configs/jdbc.properties" />

</bean>

 

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"

destroy-method="close">

<property name="driverClassName" value="${jdbc.mysql.driver}" />

<property name="url" value="${jdbc.mysql.url}" />

<property name="username" value="${jdbc.mysql.username}" />

<property name="password" value="${jdbc.mysql.password}" />

<!-- 初始化连接大小 -->

<property name="initialSize" value="${initialSize}"></property>

<!-- 连接池最大数量 -->

<property name="maxActive" value="${maxActive}"></property>

<!-- 连接池最大空闲 -->

<property name="maxIdle" value="${maxIdle}"></property>

<!-- 连接池最小空闲 -->

<property name="minIdle" value="${minIdle}"></property>

<!-- 获取连接最大等待时间 -->

<property name="maxWait" value="${maxWait}"></property>

</bean>

 

<!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">

<property name="dataSource" ref="dataSource" />

<!-- 自动扫描mapping.xml文件 -->

<property name="mapperLocations" value="classpath:com/haiersoft/buztest/mapping/*.xml"></property>

  <!-- 分页插件 -->

        <property name="plugins"> 

<list> 

<bean class="com.github.miemiedev.mybatis.paginator.OffsetLimitInterceptor"> 

<property name="dialectClass" value="com.github.miemiedev.mybatis.paginator.dialect.MySQLDialect"></property>

 </bean> 

</list> 

</property> 

</bean>

 

<!-- DAO接口所在包名,Spring会自动查找其下的类 -->

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">

<property name="basePackage" value="com.haiersoft.buztest.dao" />

<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>

</bean>

 

<!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->

<bean id="transactionManager"

class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

<property name="dataSource" ref="dataSource" />

</bean>

 

<!-- 支持注解式事务

<tx:annotation-driven transaction-manager="transactionManager" />

 -->

 

  <aop:config>

<aop:pointcut id="pointcut"

expression="execution(* com.haiersoft.buztest.service..*.*(..))" />

<aop:advisor advice-ref="txAdivce" pointcut-ref="pointcut" />

</aop:config>

<!-- 使用annotation定义事务-->

<tx:advice id="txAdivce" transaction-manager="transactionManager">

<tx:attributes>

<tx:method name="insert*" propagation="REQUIRED" rollback-for="SQLException" />

<tx:method name="save*" propagation="REQUIRED" rollback-for="SQLException" />

<tx:method name="add*" propagation="REQUIRED" rollback-for="SQLException" />

<tx:method name="update*" propagation="REQUIRED" rollback-for="SQLException"/>

<tx:method name="delete*" propagation="REQUIRED" rollback-for="SQLException" />

<tx:method name="*"  rollback-for="SQLException" read-only="true" propagation="NOT_SUPPORTED"/>

</tx:attributes>

</tx:advice>

 

</beans>

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

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

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

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

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

xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd

http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd

http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd

http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd

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

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

<!-- 定时器 写在这里会被重复执行2次

<import resource="spring4-schedule.xml"/>

研究下来发现quartz确实会加载两次:

第一次:web容器启动的时候,读取applicationContext.xml文件时,会加载一次。

第二次:Spring本身会加载applicationContext.xml一次。

-->

<!-- 视图解释类 --> 

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<property name="prefix" value="/WEB-INF/views/" />

<property name="suffix" value=".jsp" />

<property name="viewClass">

<value>org.springframework.web.servlet.view.JstlView</value>

</property>

</bean>

<!-- <aop:aspectj-autoproxy proxy-target-class="true" />  -->

<!-- 对静态资源文件的访问  方案二

访问路径带resources的

路径在location下的作为静态资源

-->  

<mvc:resources location="/WEB-INF/resources/" mapping="/resources/**"/>

<!-- 文件上传 -->  

    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />  

 

</beans>

spring-aop.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:jee="http://www.springframework.org/schema/jee"

xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"

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

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

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

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

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

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

 

<bean id="aopLog" class="com.haier.foundation.demo.forum.log.ForumLog"></bean>

<aop:config>

<aop:aspect id="aopLogAspect" ref="aopLog">

<aop:pointcut id="allMethod" expression="execution(* com.haier.foundation.demo.forum.service..*.*(..))"/>

<!-- 方法执行前 -->

<aop:before method="before" pointcut-ref="allMethod" />

<!-- 执行中 -->

<!-- <aop:around method="doAround" pointcut-ref="allMethod"/> -->

<!-- 执行后-->

<aop:after method="after" pointcut-ref="allMethod" />

<!-- 抛异常

-->

<aop:after-throwing method="doThrowing" pointcut-ref="allMethod" throwing="e"/>

 

<!-- service和dao包下方法 execution(* com.zhangx.*.dao..*.*(..))||execution(*

com.zhangx.*.service..*.*(..)) -->

<!-- 所有dao层的方法

<aop:pointcut id="daoMethod"

expression="execution(* com.zhangx.*.dao..*.*(..))" />

<aop:after-returning method="aopDaoPrint"

pointcut-ref="daoMethod" />

-->

<!-- 所有dao层的方法并传递方法入参

<aop:pointcut id="paraMethod"

expression="execution(* com.zhangx.*.dao..*.*(..)) and args(..)" />

<aop:before method="aopParaPrint" pointcut-ref="paraMethod" />

 -->

</aop:aspect>

 

</aop:config>

</beans>

Spring-interceptors

<?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:context="http://www.springframework.org/schema/context"

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

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

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

xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd

http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd

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

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

    <mvc:interceptors>  

        <mvc:interceptor>  

           <mvc:mapping path="/**"/>

           <!-- 不拦截登录页面 -->

           <mvc:exclude-mapping path="/main/**/login"/>

           <!-- 不拦截登出页面 -->

           <mvc:exclude-mapping path="/main/**/logout"/>

           <!-- 不拦截ajax请求

           <mvc:exclude-mapping path="/**/ajax/**"/>

            -->

            <!-- 不拦截验证登录请求 -->

           <mvc:exclude-mapping path="/main/checkLogin"/>

           <!-- 不拦截静态资源 -->

           <mvc:exclude-mapping path="/resources/**"/>

           <bean class="com.haiersoft.buztest.interceptor.VisitInterceptor"></bean>  

        </mvc:interceptor>  

    </mvc:interceptors>  

 

</beans>

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值