问题描述
我正在开发一个 Spring Boot 应用程序。 在我的 build.gradle 中,我添加了依赖项:
compile group: 'org.springframework',name: 'spring-test',version: '3.1.1.RELEASE'
implementation group: 'commons-io',name: 'commons-io',version: '2.6'
在我的服务中使用 Mockmultipartfile:
import org.springframework.mock.web.Mockmultipartfile;
...
...
multipartfile multipartfile = new Mockmultipartfile("file",file.getName(),"image/jpeg",IoUtils.toByteArray(input));
这是我的 build.gradle:
依赖项{
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'MysqL:mysql-connector-java'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
compile 'org.hibernate:hibernate-core:5.2.11.Final'
compile 'org.hibernate:hibernate-entitymanager:5.2.11.Final'
compile 'MysqL:mysql-connector-java'
compile 'org.apache.commons:commons-dbcp2:2.0.1'
compile 'javax.xml.bind:jaxb-api:2.3.1'
compile 'com.sun.xml.bind:jaxb-core:2.3.0'
compile 'com.sun.xml.bind:jaxb-impl:2.3.1'
compile 'javax.activation:activation:1.1.1'
compileOnly('org.projectlombok:lombok')
annotationProcessor 'org.projectlombok:lombok'
testCompile 'org.junit.jupiter:junit-jupiter-engine:5.6.2'
testCompile('org.mockito:mockito-junit-jupiter:2.23.0')
compile 'org.modelmapper:modelmapper:2.3.0'
compile 'com.google.firebase:firebase-admin:6.13.0'
compile group: 'org.springframework',version: '2.6'
}
解决方法
您使用了相当旧版本的 Spring Test:
compile group: 'org.springframework',name: 'spring-test',version: '3.1.1.RELEASE'
我假设 Spring Test 3.1.1 还没有 JUnit JUpiter SpringExtension
。将 spring-test
更新为 a more recent version 或将其从您的 build.gradle
中删除,然后让 Spring Boot 使用 Spring Boot Starter Test manage 作为 spring-test
的依赖版本。
因此,您更新后的 dependencies
部分可能如下所示:
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'mysql:mysql-connector-java'
// this is your testing swiss-army knife - take a look at its transitive dependency
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
compile 'org.hibernate:hibernate-core:5.2.11.Final'
compile 'org.hibernate:hibernate-entitymanager:5.2.11.Final'
compile 'mysql:mysql-connector-java'
compile 'org.apache.commons:commons-dbcp2:2.0.1'
compile 'javax.xml.bind:jaxb-api:2.3.1'
compile 'com.sun.xml.bind:jaxb-core:2.3.0'
compile 'com.sun.xml.bind:jaxb-impl:2.3.1'
compile 'javax.activation:activation:1.1.1'
compileOnly('org.projectlombok:lombok')
annotationProcessor 'org.projectlombok:lombok'
// REMOVE (managed by Spring Boot Starter Test) testCompile 'org.junit.jupiter:junit-jupiter-engine:5.6.2'
// REMOVE (managed by Spring Boot Starter Test) testCompile('org.mockito:mockito-junit-jupiter:2.23.0')
compile 'org.modelmapper:modelmapper:2.3.0'
compile 'com.google.firebase:firebase-admin:6.13.0'
// REMOVE compile group: 'org.springframework',version: '3.1.1.RELEASE'
implementation group: 'commons-io',name: 'commons-io',version: '2.6'