Idea导入junit5及lambda报错问题

junit5的maven依赖

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.0.0-M4</version>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>4.12.0-M4</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.0.0-M4</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.0.0-M4</version>

</dependency>

可以只导入5版本的依赖

idea不支持lambda版本问题

  • 当使用lambda时会报这样的错误
image-20210924104632261
  • 解决方案:项目名右键—->Open Moudle Setting(或者F4)—->language level
image-20210924105144550
  • 修改完后,有可能可以运行,但也有可能出现这种情况:Error:java: Compilation failed: internal java compiler error

image-20210924105452533

  • 错误原因主要是:JDK和SDK,还有Java编译编译器版本问题
  • 查看JDK和SDK版本是否一致:File—>Project Structure—>Project
image-20210924105907434

如果不一致,把它们改成一致,但是一般很少出现这种情况

  • 查看Java编译器(Java compilation):File—>Setting–>Build, Execution, Deployment–>java compilation
image-20210924110453447

或者直接pom.xml导入一个maven资源过滤也行

1
2
3
4
5
6
7
8
9
10
11
12
13
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<!--这里改成自己对应的版本号-->
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
  • 然后就运行成功了

测试参数化Csv路径问题

在maven管理工具中,要放在resources路径下,会直接找到该路径

1
@CsvFileSource(resources = "/CsvSource.csv")

spring中JdbcTemplate错误解决

1、

1
Field 'id' doesn't have a default value				//idm

解决方案:id设置自增

2、

1
org.springframework.core.type.AnnotationMetadata.introspect(Ljava/lang/Class;)Lorg/springframework/core/type/AnnotationMetadata;
image-20210929153147902

可能这两个位置搞反了


本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!