- java.lang.IllegalArgumentException: Result Maps collection already contains value for com.jjxy.dao错误
错误原因:是因为我用MyBatisGenerator,进行逆向工程时,我重复运行了几次,一开始我以为重复运行是覆盖,实际上是追加,并没有覆盖掉之前的。因此项目启动时mapper中的id就不唯一了,就会出现冲突。
错误图片:
- java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException错误
错误解释:在org/aspectj/weaver/reflect/ReflectionWorld目录下没有找到相关的类。
错误原因:因为我创建的是maven工程,我在pom.xml文件中引入了Aspects jar包,并没有引入aspectjweaver jar包,一般引入了spects jar包,其他相关联的也会自动下载到Maven Dependencies里面去。
如图所示:
虽然那里面有aspectjweaver jar包,并且打开了jar包找到了相关的目录。但事实还是报了没找到相关类的错误,于是我就在pom.xml文件中手动引入了aspectjweaver-1.8.9 jar包。本以为错误就解决了,事实上手动引入了还是会出一样的错误,这样我猜想可能是我从中央仓库下载过来后这个jar包出来什么错误,导致jar包可能不完整。这样我就换了个版本试试,试了好几个不同版本都可以,貌似就这事这各1.8.9的不行,这就很有趣了。
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.4</version>
</dependency>
- Junit版本与spring版本兼容问题
错误:
java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=testCRUD], {ExactMatcher:fDisplayName=testCRUD(com.jjxy.test.MapperTest)], {LeadingIdentifierMatcher:fClassName=com.jjxy.test.MapperTest,fLeadingIdentifier=testCRUD]] from org.junit.internal.requests.ClassRequest@6e5e91e4
at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:35)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createFilteredTest(JUnit4TestLoader.java:77)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:68)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
我用的是spring-4.3.25系列jar包,Junit是4.11.
pom.xml代码:
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.25.RELEASE</version>
</dependency>
<!-- spring-jdbc -->
<!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.25.RELEASE</version>
</dependency>
<!-- spring test -->
<!-- https://mvnrepository.com/artifact/org.springframework/spring-test -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.25.RELEASE</version>
</dependency>
<!-- spring 面向切面編程 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>4.3.25.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.4</version>
</dependency>
<!-- spring-aop 面向切面編程 -->
<!-- https://mvnrepository.com/artifact/org.springframework/spring-aop -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>4.3.25.RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
测试代码:
package com.jjxy.test;
import java.sql.Date;
import java.text.SimpleDateFormat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.jjxy.dao.DepartmentMapper;
/**
* 测试dao层的工作
* @author admin
*推荐Spring的项目就使用Spring单元测试,可以自动注入我们需要的组件
*1、导入Spring单元测试模块 spring test
*2、@ContextConfiguration指定spring配置文件的位置
*3、直接@Autowired要使用的组件即可
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:applicationContext.xml"})
public class MapperTest {
@Autowired
DepartmentMapper departmentMapper;
/**
* 测试DepartmentMapper
*/
@Test
public void testCRUD() {
/*//1、创建Spring的ioc容器
ApplicationContext ioc = new ClassPathXmlApplicationContext("applicationContext.xml");
//2、从容器中获取Mapper
DepartmentMapper bean = ioc.getBean(DepartmentMapper.class);
System.out.println(bean);*/
System.out.println(departmentMapper);
}
}
就是上述代码导致出了上面的第三个兼容错误,于是我换了个高点的Junit版本,4.12版本就可以啦。