用了springboot2.1.8版本,开发环境也是intellijidea然后问题各种频出

11:23:58.787 [scheduling-1] ERROR org.springframework.scheduling.support.TaskUtils$LoggingErrorHandler - Unexpected error occurred in scheduled task.

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.*.mapper.TestMapper.getSth

at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:235) ~[mybatis-3.5.2.jar:3.5.2]

at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:53) ~[mybatis-3.5.2.jar:3.5.2]

at org.apache.ibatis.binding.MapperProxy.lambda$cachedMapperMethod$0(MapperProxy.java:61) ~[mybatis-3.5.2.jar:3.5.2]

at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660) ~[?:1.8.0_151]

at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:61) ~[mybatis-3.5.2.jar:3.5.2]

at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:56) ~[mybatis-3.5.2.jar:3.5.2]

at com.sun.proxy.$Proxy76.getSth(Unknown Source) ~[?:?]

at com.*.service.impl.TestServiceImpl.getSth(TestServiceImpl.java:17) ~[classes/:?]

at com.*.tool.DissectData.unserilize(DissectData.java:96) ~[classes/:?]

at com.*.tool.DissectData.main(DissectData.java:103) ~[classes/:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_151]

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_151]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_151]

at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_151]

at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:84) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]

at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) [spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]

at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_151]

at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:1.8.0_151]

at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_151]

at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:1.8.0_151]

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_151]

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_151]

at java.lang.Thread.run(Thread.java:748) [?:1.8.0_151]


经过长时间排查,打开log4j的debug模式,发现如下的debug输出

11:23:57.978 [main] DEBUG org.mybatis.logging.Logger.debug(Logger.java:49) - Property 'mapperLocations' was not specified.

11:23:57.978 [main] DEBUG org.mybatis.spring.SqlSessionFactoryBean - Property 'mapperLocations' was not specified.

但是查看mapperLocations 配置的没有什么问题,只是在target包里会出现如下情况,mapper.xml文件并没有出现在目录中,而是重新建了一个com.*.mapper文件夹。

截屏2019-12-24上午11.28.22.png

最后发现在新建文件夹的时候,直接输入了com.*.mapper,而正确方法是先新建一个directory com,再新建一个directory *,在在*文件夹下新建一个mapper文件夹。

截屏2019-12-24上午11.29.16.png

这样才会报出问题。

正确之后的target文件应该是如下的样子,xml与mapper.interface在一个文件夹里:

截屏2019-12-24上午11.39.33.png

然后在启动tomcat会出现如下的报错:


Caused by: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: 2 字节的 UTF-8 序列的字节 2 无效。

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name '*Application': Unsatisfied dependency expressed through field 'lagouService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'lagouService': Unsatisfied dependency expressed through field 'lagouMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'lagouMapper' defined in file [/Users/IdeaProjects/tx/target/classes/com/mapper/LagouMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [/Users/IdeaProjects/tx/target/classes/com//ServletInitializer.class]'; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: 2 字节的 UTF-8 序列的字节 2 无效。

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'lagouService': Unsatisfied dependency expressed through field 'lagouMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'lagouMapper' defined in file [/Users/IdeaProjects//target/classes/com/mapper/LagouMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [/Users/IdeaProjects//target/classes/com//ServletInitializer.class]'; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: 2 字节的 UTF-8 序列的字节 2 无效。

at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:596) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]