SpringMVC+Mybatis架构中的问题记录

2014/08/16 记录

今天遇到个问题。折腾了我大约4个小时,好坑啊由于之前没遇到过

我的包是这么分的:com.project名.模块名.service.impl     在spring 配置这个切面 execution(* com.project名..*Impl.*(..)) 他 就是找不到com.project名.模块名.service.impl以下的*Impl类

而且此配置就算配错了,他不报错,而且当我同一时候用junit測试,同一时候载入三个配置文件 springMVC.xml spring.xml spring-mybatis.xml 它有正常,一旦通过web初始化就出问题,假设web同一时候载入三个文件也不会出问题。当他这样配置时仅仅会在日志文件里记录例如以下:

DEBUG - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@15872f5] was not registered for synchronization because synchronization is not active
DEBUG - Fetching JDBC Connection from DataSource
DEBUG - JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@152f43b] will not be managed by Spring
DEBUG - ooo Using Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@152f43b]
DEBUG - ==>  Preparing: select * from test where testid=?

 
DEBUG - ==> Parameters: 1(Integer)
DEBUG - <==      Total: 1
DEBUG - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@15872f5]
DEBUG - Returning JDBC Connection to DataSource

这里显示的是Spring没有去管理数据库的事务。后来发现问题,是SpringMVC扫描的时候载入了Service的bean,在Spring在扫描的时候就不再将Service扫描进去。从而Spring在配置事物的时候失效。

所以在配置文件中,将SpringMVC 要配置仅仅扫秒带controller注解的类。


2015/10/20 Spring 3.X的项目在jdk 1.7 编译之后在jdk1.8 下用不了,报context初始化异常。另外mysql配置文件中不能有表达式,应该直接写数值比方max_allowed_packet=2*1024*1024 这样是错误的。

要max_allowed_packet=2097152

原文地址:https://www.cnblogs.com/zsychanpin/p/7193791.html