mybatis报错:The alias ‘xxx’ is already mapped to the value ‘*.*.xxx’
先贴上我所遇到的异常,这是我在IDEA上启动iBase4J时遇到的错误:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2018-11-19 13:43:20.925 [localhost-startStop-1] ERROR [SpringApplication:842] - Application run failed org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'coreTask': Unsatisfied dependency expressed through field 'sessionService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sysSessionServiceImpl': Unsatisfied dependency expressed through field 'mapper'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sysSessionMapper' defined in file [D:\Workspace\IDEAProjects\iBase4J\iBase4J-SYS-Service\target\iBase4J-SYS-Service\WEB-INF\classes\org\ibase4j\mapper\SysSessionMapper.class]: Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [top/ibase4j/core/config/MyBatisConfig.class]: Invocation of init method failed; nested exception is org.apache.ibatis.type.TypeException: The alias 'MultipleFailureException' is already mapped to the value 'org.junit.runners.model.MultipleFailureException'. at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:587) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] ......
异常重点是:
org.apache.ibatis.type.TypeException: The alias ‘MultipleFailureException’ is already mapped to the value ‘org.junit.runners.model.MultipleFailureException’.
经过分析,原来是因为配置文件中,mybatis指定别名时,指定的是一个路径mybatis.typeAliasesPackage=*.**.model*,而不是一个具体类或者固定路径的包,恰巧该项目依赖的jar包中,存在同名类或者包。把
*.**.model*
修改为org.ibase4j.model*再启动就不报错了。这种问题,可以在配置文件中搜索Aliases,先找到在哪里配置的别名。