本文主要是介绍will not be managed by Spring 和was not registered for synchronization because synchronization is not,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
原文地址:http://blog.csdn.net/xufan007/article/details/52025201
在SpringMVC框架,事物管理杜绝出现 will not be managed by Spring 和was not registered for synchronization because synchronization is not active
否则Mybatis的事物管理中对事物的控制会出问题。
web.xml的加载顺序为:注意web.xml的执行顺序 context-param -> listener -> filter -> servlet
如果在SpringMCV中使用注解方式,建议清晰定义注解的作用,避免各个层级之间应为初级程序员造成的注解混乱问题;
应该保证各个配置文件功能单一,避免架构混乱
直接上代码:、
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>SingLoginA</display-name>
<!-- 编码过滤器 -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<async-supported>true</async-supported>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 防止Spring内存溢出监听器 -->
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
<!-- 使Spring支持request与session的scope,如:<bean id="loginAction" scope="request"/> -->
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<!-- 日志 -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>WEB-INF/classes/log4j.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<!-- Spring MVC servlet -->
<servlet>
<servlet-name>SpringMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>SpringMVC</servlet-name>
<!-- 此处可以可以配置成*.do,对应struts的后缀习惯 -->
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/index.jsp</welcome-file>
</welcome-file-list>
<!-- 配置SESSION超时,单位是分钟 -->
<session-config>
<session-timeout>15</session-timeout>
</session-config>
<!-- Spring监听器 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:spring-mybatis.xml,
classpath*:servlet-init.xml,
<!-- classpath*:spring-mybatis.xml,, -->
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 阿里巴巴数据库连接池 -->
<filter>
<filter-name>druidWebStatFilter</filter-name>
<filter-class>com.alibaba.druid.support.http.WebStatFilter</filter-class>
<init-param>
<param-name>exclusions</param-name>
<param-value>*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>druidWebStatFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>druidStatView</servlet-name>
<servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>druidStatView</servlet-name>
<url-pattern>/druid/*</url-pattern>
</servlet-mapping>
<!-- 系统启动时候加载的服务 -->
<servlet>
<description></description>
<servlet-name>borrowServlet</servlet-name>
<servlet-class>com.sing.common.util.sevlet.InitService</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>test</param-value>
</init-param>
<load-on-startup>10</load-on-startup>
</servlet>
</web-app>
##########################
Spring-init.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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util" 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-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-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/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<!--
properties文件引入方式
<context:property-placeholder location="classpath*:dataSourceConfig.properties" />
或则
-->
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:/dataSourceConfig.properties</value>
</list>
</property>
</bean>
<!-- 注意web.xml的执行顺序 context-param -> listener -> filter -> servlet
避免在SpringMVC中启用 service注解,否则Spring管理不了数据库事物
<context:component-scan base-package="com.sing.service" />
如下为线上指出注解用于何处切com.sing.service 允许用Service
-->
<context:component-scan base-package="com.sing.service" >
<context:include-filter type="annotation" expression="org.springframework.stereotype.Service"/>
<!-- 拦截所有的在service层使用 @service注解的类 主要是为了层级更加清晰以及避免注解乱用-->
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<property name="url" value="${url}" />
<property name="username" value="${username}" />
<property name="password" value="${password}" />
<property name="initialSize" value="${initialSize}" />
<property name="minIdle" value="${minIdle}" />
<property name="maxActive" value="${maxActive}" />
<property name="maxWait" value="${maxWait}" />
<!-- timeBetweenEvictionRunsMillis毫秒秒检查一次连接池中空闲的连接,把空闲时间超过minEvictableIdleTimeMillis毫秒的连接断开,直到连接池中的连接数到minIdle为止 -->
<property name="timeBetweenEvictionRunsMillis" value="${BEtime}" />
<property name="minEvictableIdleTimeMillis" value="${minEtime}" />
<property name="validationQuery" value="SELECT 'x'" />
<property name="testWhileIdle" value="true" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />
<property name="poolPreparedStatements" value="${poolPreparedStatements}" />
<property name="maxPoolPreparedStatementPerConnectionSize" value="${maxPoolPreparedStatementPerConnectionSize}" />
<property name="removeAbandoned" value="${removeAbandoned}" /> <!-- 打开removeAbandoned功能 -->
<property name="removeAbandonedTimeout" value="${removeAbandonedTimeout}" /> <!-- 1800秒,也就是30分钟 -->
<property name="logAbandoned" value="${logAbandoned}" /> <!-- 关闭abanded连接时输出错误日志 -->
<property name="filters" value="mergeStat" />
<property name="connectionProperties" value="druid.stat.slowSqlMillis=5000" />
</bean>
<!--做双数据源-->
<bean id="readDataSource" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<property name="url" value="${readUrl}" />
<property name="username" value="${readUsername}" />
<property name="password" value="${readPassword}" />
<property name="initialSize" value="${initialSize}" />
<property name="minIdle" value="${minIdle}" />
<property name="maxActive" value="${maxActive}" />
<property name="maxWait" value="${maxWait}" />
<!-- timeBetweenEvictionRunsMillis毫秒秒检查一次连接池中空闲的连接,把空闲时间超过minEvictableIdleTimeMillis毫秒的连接断开,直到连接池中的连接数到minIdle为止 -->
<property name="timeBetweenEvictionRunsMillis" value="${BEtime}" />
<property name="minEvictableIdleTimeMillis" value="${minEtime}" />
<property name="validationQuery" value="SELECT 'x'" />
<property name="testWhileIdle" value="true" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />
<property name="poolPreparedStatements" value="${poolPreparedStatements}" />
<property name="maxPoolPreparedStatementPerConnectionSize" value="${maxPoolPreparedStatementPerConnectionSize}" />
<property name="removeAbandoned" value="${removeAbandoned}" /> <!-- 打开removeAbandoned功能 -->
<property name="removeAbandonedTimeout" value="${removeAbandonedTimeout}" /> <!-- 1800秒,也就是30分钟 -->
<property name="logAbandoned" value="${logAbandoned}" /> <!-- 关闭abanded连接时输出错误日志 -->
<property name="filters" value="mergeStat" />
<!-- <property name="filters" value="stat" /> -->
<property name="connectionProperties" value="druid.stat.slowSqlMillis=5000" />
<!-- <property name="useGloalDataSourceStat" value="true" /> -->
</bean>
<!--
<bean id="multipleDataSource" class="org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource">
<property name="defaultTargetDataSource" ref="dataSource"/>
<property name="targetDataSources">
<map>
<entry key="dataSource" value-ref="dataSource"/>
<entry key="readDataSource" value-ref="readDataSource"/>
</map>
</property>
</bean>
-->
<bean id="druid-stat-interceptor"
class="com.alibaba.druid.support.spring.stat.DruidStatInterceptor" />
<bean id="druid-stat-pointcut" class="org.springframework.aop.support.JdkRegexpMethodPointcut"
scope="prototype">
<property name="patterns">
<list>
<value>com.cn.sing.service.*</value>
</list>
</property>
</bean>
<aop:config>
<aop:advisor advice-ref="druid-stat-interceptor"
pointcut-ref="druid-stat-pointcut" />
</aop:config>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 避免 will not be managed by Spring
和was not registered for synchronization because synchronization is not active
一定要是事物被Spring管理,否则事物不起作用
-->
<!--注解式事物会在上下文中寻找使用@Transactional的注解的类和方法,启用事物
申明式事物会在拦截execution(* com.sing.service..*.*(..))的切面中寻找对应的
其中:第一个*代表所有的返回值类型
第二个*代表所有的类
第三个*代表类所有方法 最后一个..代表所有的参数。
拦截方法使用事物,其中事物的加载方式根据 事物在配置文件的位置有关系,
例如,声明式事物在注解式事物之前,则会以声明式事物的拦截事物为主,其拦截不到的时候
才会自动去匹配注解式事物,
如果想使用两种事物方式兼容,建议注解式事物在声明式事物之前
-->
<!-- 注解式事物 -->
<tx:annotation-driven transaction-manager="transactionManager" />
<!-- 声明式事物-->
<aop:config>
<aop:advisor pointcut="execution(* com.sing.service..*.*(..))" advice-ref="txAdvice" />
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="load*" read-only="true" />
<tx:method name="select*" />
<tx:method name="*" propagation="REQUIRED" rollback-for="Exception" />
</tx:attributes>
</tx:advice>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mapperLocations" value="classpath*:com/sing/dao/mapper/*.xml" />
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.sing.dao" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>
</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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util" 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-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-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/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<!--
properties文件引入方式
<context:property-placeholder location="classpath*:dataSourceConfig.properties" />
或则
-->
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:/dataSourceConfig.properties</value>
</list>
</property>
</bean>
<!-- 注意web.xml的执行顺序 context-param -> listener -> filter -> servlet
避免在SpringMVC中启用 service注解,否则Spring管理不了数据库事物
<context:component-scan base-package="com.sing.service" />
如下为线上指出注解用于何处切com.sing.service 允许用Service
-->
<context:component-scan base-package="com.sing.service" >
<context:include-filter type="annotation" expression="org.springframework.stereotype.Service"/>
<!-- 拦截所有的在service层使用 @service注解的类 主要是为了层级更加清晰以及避免注解乱用-->
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<property name="url" value="${url}" />
<property name="username" value="${username}" />
<property name="password" value="${password}" />
<property name="initialSize" value="${initialSize}" />
<property name="minIdle" value="${minIdle}" />
<property name="maxActive" value="${maxActive}" />
<property name="maxWait" value="${maxWait}" />
<!-- timeBetweenEvictionRunsMillis毫秒秒检查一次连接池中空闲的连接,把空闲时间超过minEvictableIdleTimeMillis毫秒的连接断开,直到连接池中的连接数到minIdle为止 -->
<property name="timeBetweenEvictionRunsMillis" value="${BEtime}" />
<property name="minEvictableIdleTimeMillis" value="${minEtime}" />
<property name="validationQuery" value="SELECT 'x'" />
<property name="testWhileIdle" value="true" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />
<property name="poolPreparedStatements" value="${poolPreparedStatements}" />
<property name="maxPoolPreparedStatementPerConnectionSize" value="${maxPoolPreparedStatementPerConnectionSize}" />
<property name="removeAbandoned" value="${removeAbandoned}" /> <!-- 打开removeAbandoned功能 -->
<property name="removeAbandonedTimeout" value="${removeAbandonedTimeout}" /> <!-- 1800秒,也就是30分钟 -->
<property name="logAbandoned" value="${logAbandoned}" /> <!-- 关闭abanded连接时输出错误日志 -->
<property name="filters" value="mergeStat" />
<property name="connectionProperties" value="druid.stat.slowSqlMillis=5000" />
</bean>
<bean id="readDataSource" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<property name="url" value="${readUrl}" />
<property name="username" value="${readUsername}" />
<property name="password" value="${readPassword}" />
<property name="initialSize" value="${initialSize}" />
<property name="minIdle" value="${minIdle}" />
<property name="maxActive" value="${maxActive}" />
<property name="maxWait" value="${maxWait}" />
<!-- timeBetweenEvictionRunsMillis毫秒秒检查一次连接池中空闲的连接,把空闲时间超过minEvictableIdleTimeMillis毫秒的连接断开,直到连接池中的连接数到minIdle为止 -->
<property name="timeBetweenEvictionRunsMillis" value="${BEtime}" />
<property name="minEvictableIdleTimeMillis" value="${minEtime}" />
<property name="validationQuery" value="SELECT 'x'" />
<property name="testWhileIdle" value="true" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />
<property name="poolPreparedStatements" value="${poolPreparedStatements}" />
<property name="maxPoolPreparedStatementPerConnectionSize" value="${maxPoolPreparedStatementPerConnectionSize}" />
<property name="removeAbandoned" value="${removeAbandoned}" /> <!-- 打开removeAbandoned功能 -->
<property name="removeAbandonedTimeout" value="${removeAbandonedTimeout}" /> <!-- 1800秒,也就是30分钟 -->
<property name="logAbandoned" value="${logAbandoned}" /> <!-- 关闭abanded连接时输出错误日志 -->
<property name="filters" value="mergeStat" />
<!-- <property name="filters" value="stat" /> -->
<property name="connectionProperties" value="druid.stat.slowSqlMillis=5000" />
<!-- <property name="useGloalDataSourceStat" value="true" /> -->
</bean>
<!--
<bean id="multipleDataSource" class="org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource">
<property name="defaultTargetDataSource" ref="dataSource"/>
<property name="targetDataSources">
<map>
<entry key="dataSource" value-ref="dataSource"/>
<entry key="readDataSource" value-ref="readDataSource"/>
</map>
</property>
</bean>
-->
<bean id="druid-stat-interceptor"
class="com.alibaba.druid.support.spring.stat.DruidStatInterceptor" />
<bean id="druid-stat-pointcut" class="org.springframework.aop.support.JdkRegexpMethodPointcut"
scope="prototype">
<property name="patterns">
<list>
<value>com.cn.sing.service.*</value>
</list>
</property>
</bean>
<aop:config>
<aop:advisor advice-ref="druid-stat-interceptor"
pointcut-ref="druid-stat-pointcut" />
</aop:config>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 避免 will not be managed by Spring
和was not registered for synchronization because synchronization is not active
一定要是事物被Spring管理,否则事物不起作用
-->
<!--注解式事物会在上下文中寻找使用@Transactional的注解的类和方法,启用事物
申明式事物会在拦截execution(* com.sing.service..*.*(..))的切面中寻找对应的
其中:第一个*代表所有的返回值类型
第二个*代表所有的类
第三个*代表类所有方法 最后一个..代表所有的参数。
拦截方法使用事物,其中事物的加载方式根据 事物在配置文件的位置有关系,
例如,声明式事物在注解式事物之前,则会以声明式事物的拦截事物为主,其拦截不到的时候
才会自动去匹配注解式事物,
如果想使用两种事物方式兼容,建议注解式事物在声明式事物之前
-->
<!-- 注解式事物 -->
<tx:annotation-driven transaction-manager="transactionManager" />
<!-- 声明式事物-->
<aop:config>
<aop:advisor pointcut="execution(* com.sing.service..*.*(..))" advice-ref="txAdvice" />
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="load*" read-only="true" />
<tx:method name="select*" />
<tx:method name="*" propagation="REQUIRED" rollback-for="Exception" />
</tx:attributes>
</tx:advice>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mapperLocations" value="classpath*:com/sing/dao/mapper/*.xml" />
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.sing.dao" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>
</beans>
Spring.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:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 自动扫描该包,使SpringMVC认为包下用了@controller注解的类是控制器
<context:component-scan base-package="com.sing.controller" />
-->
<context:component-scan base-package="com.sing.controller" >
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/>
</context:component-scan>
<!--
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath*:*.properties</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>
-->
<!--避免IE执行AJAX时,返回JSON出现下载文件 -->
<bean id="mappingJacksonHttpMessageConverter"
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>
<!-- 启动SpringMVC的注解功能,完成请求和注解POJO的映射 -->
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="mappingJacksonHttpMessageConverter" /> <!-- JSON转换器 -->
</list>
</property>
</bean>
<!-- MVC注解驱动 -->
<mvc:annotation-driven />
<!-- 指定静态资源目录 -->
<mvc:default-servlet-handler />
<mvc:resources mapping="/baseJs/**" location="/WEB-INF/page/*.js"/>
<!-- 自定义拦截器:继承HandlerInterceptor实现拦截 -->
<mvc:interceptors>
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
<mvc:interceptor>
<mvc:mapping path="/**" />
<bean class="com.sing.common.util.interceptor.SessionAllInterceptor">
<property name="excludeUrls">
<list>
<value>/haocai/assets/subregister</value>
</list>
</property>
</bean>
</mvc:interceptor>
<!--
<mvc:interceptor>
<mvc:mapping path="/**" />
<bean class="com.sing.common.util.interceptor.SessionAllInterceptor">
</bean>
</mvc:interceptor> -->
</mvc:interceptors>
<!-- 自定义异常拦截器 -->
<bean id="exceptionResolver" class="com.sing.common.util.interceptor.ExceptionInterceptor"/>
<!-- 定义跳转的文件的前后缀 ,视图模式配置-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 这里的配置我的理解是自动给后面action的方法return的字符串加上前缀和后缀,变成一个 可用的url地址 -->
<property name="prefix" value="/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- 配置文件上传,如果没有使用文件上传可以不用配置,当然如果不配,那么配置文件中也不必引入上传组件包 -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- 默认编码 -->
<property name="defaultEncoding" value="utf-8" />
<!-- 文件大小最大值 -->
<property name="maxUploadSize" value="10485760000" />
<!-- 内存中的最大值 -->
<property name="maxInMemorySize" value="40960" />
</bean>
</beans>
这篇关于will not be managed by Spring 和was not registered for synchronization because synchronization is not的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!