解决tkmapper通⽤mapper的bug问题
如下所⽰:
<bean class="tk.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="batis.mapper"/>
<property name="properties">
<value>
batis.mappermon.Mapper
</value>
</property>
</bean>
basePackage的属性值不能包含通⽤mapper所在的包
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-03-14 12:39:21.741 ERROR [main] [hio-sys] o.s.boot.SpringApplication - Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tk.mybatis.mapper.autoconfigure.MapperAutoConfiguration': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationExcept at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:137)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:409)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1620)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
at org.springframework.beans.factory.ateBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.Object(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.Singleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.Bean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
at t.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
at t.support.AbstractApplicationContext.__refresh(AbstractApplicationContext.java:543)
at t.support.AbstractApplicationContext.jrLockAndRefresh(AbstractApplicationContext.java)
at t.fresh(AbstractApplicationContext.java)
at org.t.fresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.fresh(SpringApplication.java:693)
at org.springframework.freshContext(SpringApplication.java:360)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at com.jzy.hio.HioSysApplication.main(HioSysApplication.java:35)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'baseMapper' defined in file [C:\Users\coffee\OneDrive\workspace\v2r1-hio-base\target\classes\com\jzy\hio\base\mapper\BaseMapper.class]: Invocation of in at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
at org.springframework.beans.factory.ateBean(AbstractAutowireCapableBeanFactory.java:483)
springframework jar包下载at org.springframework.beans.factory.support.Object(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.Singleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.Bean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.BeansOfType_jrOrig(DefaultListableBeanFactory.java:519)
at org.springframework.beans.factory.BeansOfType(DefaultListableBeanFactory.java)
at org.springframework.beans.factory.BeansOfType_jrOrig(DefaultListableBeanFactory.java:508)
at org.springframework.beans.factory.BeansOfType(DefaultListableBeanFactory.java)
at t.BeansOfType(AbstractApplicationContext.java:1188)
batis.mapper.autoconfigure.MapperAutoConfiguration.addPageInterceptor(MapperAutoConfiguration.java:71)
flect.NativeMethodAccessorImpl.invoke0(Native Method)
flect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
flect.DelegatingMethodAccessorImpl.__invoke(DelegatingMethodAccessorImpl.java:43)
flect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java)
flect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java)
at flect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:366)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:311)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:134)
.
.. 18 common frames omitted
Caused by: tk.mybatis.mapper.MapperException: tk.mybatis.mapper.MapperException: java.lang.ClassCastException: flectiveObjects.TypeVariableImpl cannot be cast to java.lang.Class
batis.mapper.mapperhelper.MapperHelper.setSqlSource(MapperHelper.java:248)
batis.mapper.mapperhelper.MapperHelper.processConfiguration(MapperHelper.java:311)
batis.spring.mapper.MapperFactoryBean.checkDaoConfig(MapperFactoryBean.java:54)
at org.springframework.dao.support.DaoSupport.afterPropertiesSet(DaoSupport.java:44)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
... 39 common frames omitted
Caused by: tk.mybatis.mapper.MapperException: java.lang.ClassCastException: flectiveObjects.TypeVariableImpl cannot be cast to java.lang.Class
batis.mapper.mapperhelper.MapperTemplate.setSqlSource(MapperTemplate.java:258)
batis.mapper.mapperhelper.MapperHelper.setSqlSource(MapperHelper.java:245)
... 44 common frames omitted
Caused by: java.lang.ClassCastException: flectiveObjects.TypeVariableImpl cannot be cast to java.lang.Class
batis.mapper.EntityClass(MapperTemplate.java:290)
batis.mapper.provider.base.BaseSelectProvider.selectOne(BaseSelectProvider.java:50)
flect.NativeMethodAccessorImpl.invoke0(Native Method)
flect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
flect.DelegatingMethodAccessorImpl.__invoke(DelegatingMethodAccessorImpl.java:43)
flect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java)
flect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java)
at flect.Method.invoke(Method.java:498)
batis.mapper.mapperhelper.MapperTemplate.setSqlSource(MapperTemplate.java:246)
... 45 common frames omitted
(通⽤mapper)项⽬升级通⽤Mapper引发的⼀连串问题以及问题解决
项⽬环境
通⽤Mapper版本
<dependency>
<groupId&batis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>1.1.5</version>
</dependency>
Spring boot版本
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath />
</parent>
公司统⼀封装了三个核⼼包(kemean-aid、kemean-third、kemean-web),平时技术开发都是把三核⼼包下载源码到本地启动运⾏,这个星期把三个核⼼包打包成jar,让项⽬依赖jar启动,但启动的时
候报了⼀个maven错误(问题⼀)。
问题⼀
Caused by: java.lang.LinkageError: loader constraint violation: loader (instance of org/springframework/boot/devtools/restart/classloader/RestartClassLoader) previously initiated loading for a
different type with name "tk/mybatis/mapper/common/Mapper"
<dependency>
<groupId&batis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>2.0.4</version>
</dependency>
以下的问题都是在2版本的通⽤mapper中遇到的
问题⼆
问题解决
修改启动类@MapperScan注解
2版本的通⽤Mapper提供了@MapperScan注解,之前我们使⽤的是batis.spring.annotation.MapperScan,现需把@MapperScan改为tk.mybatis.spring.annotation.MapperScan
添加spring-devtools.properties⽂件
在项⽬src/main/resources⽬录新建⼀个⽂件夹META-INF(项⽬右键-new-Source Folder),添加热部署配置⽂件spring-devtools.properties,在⽂件⾥⾯添加
restart.includepanycommonlibs=tk/mybatis.*
问题三
github也有此问题的讨论:
问题解决:把项⽬热部署去掉
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
在处理完问题⼆、三,通⽤Mapper就升级成功了,项⽬也能够正常启动访问,但是,咱们在处理问题三的时候,把spring boot的热部署给去掉了,这就意味着咱们⽇后每改动⼀点,都需要重新启动部署服务,这是⼠可忍,叔不可忍;叔可忍,婶也不能忍的操作啊。
尝试过好多⽅式,都不能“升级通⽤mapper2版本”与“保留Spring boot热部署”两个兼得,后来看到这哥们的⼀句话,给了我⼀个提醒,于是乎在刚才添加的spring-devtools.properties⽂件再补充⼀⾏restart.includepanycommonlibs=kemean.*
spring-devtools.properties内容(kemean.*是公司jar的前缀)
restart.includepanycommonlibs=tk/mybatis.*
restart.includepanycommonlibs=kemean.*
再启动服务,服务正常使⽤,热部署也能够保留
问题⼀的最终解决
结合问题三的解决思路,那么咱们在不升级通⽤mapper的前提下,让项⽬依赖打包出来的jar运⾏,则仅需在
项⽬src/main/resources⽬录新建⼀个⽂件夹META-INF(项⽬右键-new-Source Folder),添加热部署配置⽂件spring-devtools.properties,在⽂件⾥⾯添加
restart.includepanycommonlibs=kemean.*
问题⼀就在不升级通⽤mapper下完美解决了~
以上为个⼈经验,希望能给⼤家⼀个参考,也希望⼤家多多⽀持。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论