我项目说springcloud分布式项目,然后有些老模块用的是mybatis,而新模块我用的是mybatisplus,然而依赖没有处理好,旧模块启动老是报错,使用mybatisplus的模块启动正常,以下是报错信息,搞了2天都没有找到是不是有controller的url冲突等问题
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.ArrayStoreException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1778)
解决办法:
在要使用mybatis的模块中把mybatiplus的冲突依赖(mybatis-spring、mybatis)给排除掉即可
<dependency><!--mybatis-plus包含了,mybatis-spring-boot-starter 的核心功能,因此可以移除 mybatis-spring-boot-starter-->
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
<exclusions>
<exclusion>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
</exclusion>
<exclusion>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
</exclusion>
</exclusions>
</dependency>
如果还没有解决,那么再看看,以下2个有没有问题(看注释):
private final RedisTemplate<String, String> redisTemplate; //不能使用@Autowired,而是要写一个构造方法入参然后再用@Autowired,如下:
@Autowired
public 类名(RedisTemplate<String, String> redisTemplate) {
this.redisTemplate = redisTemplate;
}
@Autowired
StringRedisTemplate redisTemplate; //必须使用@Autowired,而不能使用@Resource