请在迁移到 Spring Boot 3.2 后运行 JUnit 测试时遇到问题。当一起运行测试时,它们会失败,但会单独通过。 methodSignature.getParameterNames() 为 null
我正在使用 Intellij IDEA。 maven项目依赖树是:
[INFO] | +- org.springframework.boot:spring-boot-starter:jar:3.2.10:compile
[INFO] | | +- org.springframework.boot:spring-boot:jar:3.2.10:compile
[INFO] | | +- org.springframework.boot:spring-boot-autoconfigure:jar:3.2.10:compile
[INFO] | | +- org.springframework.boot:spring-boot-starter-logging:jar:3.2.10:compile
[INFO] | | | +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.21.1:compile
[INFO] | | | \- org.slf4j:jul-to-slf4j:jar:2.0.16:compile
[INFO] | | +- jakarta.annotation:jakarta.annotation-api:jar:2.1.1:compile
[INFO] | | \- org.yaml:snakeyaml:jar:2.2:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-json:jar:3.2.10:compile
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.15.4:compile
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.15.4:compile
[INFO] | | \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.15.4:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-aop:jar:3.2.10:compile
[INFO] | | +- org.springframework:spring-aop:jar:6.1.13:compile
[INFO] | | \- org.aspectj:aspectjweaver:jar:1.9.22.1:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-databind:jar:2.15.4:compile
[INFO] | | \- com.fasterxml.jackson.core:jackson-annotations:jar:2.15.4:compile
[INFO] | +- com.fasterxml.jackson.dataformat:jackson-dataformat-csv:jar:2.15.4:compile
[INFO] | +- net.logstash.logback:logstash-logback-encoder:jar:7.0.1:compile
[INFO] | +- org.apache.poi:poi:jar:5.3.0:compile
[INFO] | | +- commons-codec:commons-codec:jar:1.16.1:compile
[INFO] | | +- org.apache.commons:commons-collections4:jar:4.4:compile
[INFO] | | +- org.apache.commons:commons-math3:jar:3.6.1:compile
[INFO] | | +- commons-io:commons-io:jar:2.16.1:compile
[INFO] | | +- com.zaxxer:SparseBitSet:jar:1.3:compile
[INFO] | | \- org.apache.logging.log4j:log4j-api:jar:2.21.1:compile
[INFO] | +- org.apache.poi:poi-ooxml:jar:5.3.0:compile
[INFO] | | +- org.apache.poi:poi-ooxml-lite:jar:5.3.0:compile
[INFO] | | +- org.apache.xmlbeans:xmlbeans:jar:5.2.1:compile
[INFO] | | +- org.apache.commons:commons-compress:jar:1.26.2:compile
[INFO] | | \- com.github.virtuald:curvesapi:jar:1.08:compile
[INFO] | \- org.apache.commons:commons-lang3:jar:3.13.0:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:3.2.10:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-tomcat:jar:3.2.10:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-core:jar:10.1.30:compile
[INFO] | | \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:10.1.30:compile
[INFO] | +- org.springframework:spring-web:jar:6.1.13:compile
[INFO] | | +- org.springframework:spring-beans:jar:6.1.13:compile
[INFO] | | \- io.micrometer:micrometer-observation:jar:1.12.10:compile
[INFO] | | \- io.micrometer:micrometer-commons:jar:1.12.10:compile
[INFO] | \- org.springframework:spring-webmvc:jar:6.1.13:compile
[INFO] | +- org.springframework:spring-context:jar:6.1.13:compile
[INFO] | \- org.springframework:spring-expression:jar:6.1.13:compile
[INFO] +- org.springframework.boot:spring-boot-starter-webflux:jar:3.2.10:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-reactor-netty:jar:3.2.10:compile
[INFO] | | \- io.projectreactor.netty:reactor-netty-http:jar:1.1.22:compile
[INFO] | | +- io.netty:netty-codec-http:jar:4.1.113.Final:compile
[INFO] | | | +- io.netty:netty-common:jar:4.1.113.Final:compile
[INFO] | | | +- io.netty:netty-buffer:jar:4.1.113.Final:compile
[INFO] | | | +- io.netty:netty-transport:jar:4.1.113.Final:compile
[INFO] | | | +- io.netty:netty-codec:jar:4.1.113.Final:compile
[INFO] | | | \- io.netty:netty-handler:jar:4.1.113.Final:compile
[INFO] | | +- io.netty:netty-codec-http2:jar:4.1.113.Final:compile
[INFO] | | +- io.netty:netty-resolver-dns:jar:4.1.113.Final:compile
[INFO] | | | +- io.netty:netty-resolver:jar:4.1.113.Final:compile
[INFO] | | | \- io.netty:netty-codec-dns:jar:4.1.113.Final:compile
[INFO] | | +- io.netty:netty-resolver-dns-native-macos:jar:osx-x86_64:4.1.113.Final:compile
[INFO] | | | \- io.netty:netty-resolver-dns-classes-macos:jar:4.1.113.Final:compile
[INFO] | | +- io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.1.113.Final:compile
[INFO] | | | +- io.netty:netty-transport-native-unix-common:jar:4.1.113.Final:compile
[INFO] | | | \- io.netty:netty-transport-classes-epoll:jar:4.1.113.Final:compile
[INFO] | | \- io.projectreactor.netty:reactor-netty-core:jar:1.1.22:compile
[INFO] | | \- io.netty:netty-handler-proxy:jar:4.1.113.Final:compile
[INFO] | | \- io.netty:netty-codec-socks:jar:4.1.113.Final:compile
[INFO] | \- org.springframework:spring-webflux:jar:6.1.13:compile
[INFO] | \- io.projectreactor:reactor-core:jar:3.6.10:compile
[INFO] | \- org.reactivestreams:reactive-streams:jar:1.0.4:compile
[INFO] +- org.springframework.boot:spring-boot-starter-amqp:jar:3.2.10:compile
[INFO] | +- org.springframework:spring-messaging:jar:6.1.13:compile
[INFO] | \- org.springframework.amqp:spring-rabbit:jar:3.1.7:compile
[INFO] | +- org.springframework.amqp:spring-amqp:jar:3.1.7:compile
[INFO] | | \- org.springframework.retry:spring-retry:jar:2.0.9:compile
[INFO] | +- com.rabbitmq:amqp-client:jar:5.19.0:compile
[INFO] | \- org.springframework:spring-tx:jar:6.1.13:compile
[INFO] +- org.springframework.boot:spring-boot-starter-validation:jar:3.2.10:compile
[INFO] | +- org.apache.tomcat.embed:tomcat-embed-el:jar:10.1.30:compile
[INFO] | \- org.hibernate.validator:hibernate-validator:jar:8.0.1.Final:compile
[INFO] | +- jakarta.validation:jakarta.validation-api:jar:3.0.2:compile
[INFO] | +- org.jboss.logging:jboss-logging:jar:3.5.3.Final:compile
[INFO] | \- com.fasterxml:classmate:jar:1.6.0:compile
[INFO] +- org.springframework.boot:spring-boot-configuration-processor:jar:3.2.10:compile (optional)
[INFO] +- org.springframework.boot:spring-boot-starter-freemarker:jar:3.2.10:compile
[INFO] | +- org.freemarker:freemarker:jar:2.3.33:compile
[INFO] | \- org.springframework:spring-context-support:jar:6.1.13:compile
[INFO] +- org.projectlombok:lombok:jar:1.18.34:compile
[INFO] +- com.fasterxml.jackson.core:jackson-core:jar:2.13.1:compile
[INFO] +- ch.qos.logback:logback-access:jar:1.4.14:compile
[INFO] +- ch.qos.logback:logback-classic:jar:1.4.14:compile
[INFO] | \- org.slf4j:slf4j-api:jar:2.0.16:compile
[INFO] +- ch.qos.logback:logback-core:jar:1.4.14:compile
[INFO] +- commons-beanutils:commons-beanutils:jar:1.9.4:compile
[INFO] | +- commons-logging:commons-logging:jar:1.2:compile
[INFO] | \- commons-collections:commons-collections:jar:3.2.2:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:3.2.10:test
[INFO] | +- org.springframework.boot:spring-boot-test:jar:3.2.10:test
[INFO] | +- org.springframework.boot:spring-boot-test-autoconfigure:jar:3.2.10:test
[INFO] | +- com.jayway.jsonpath:json-path:jar:2.9.0:test
[INFO] | +- jakarta.xml.bind:jakarta.xml.bind-api:jar:4.0.2:test
[INFO] | | \- jakarta.activation:jakarta.activation-api:jar:2.1.3:test
[INFO] | +- net.minidev:json-smart:jar:2.5.1:test
[INFO] | | \- net.minidev:accessors-smart:jar:2.5.1:test
[INFO] | | \- org.ow2.asm:asm:jar:9.6:test
[INFO] | +- org.assertj:assertj-core:jar:3.24.2:test
[INFO] | +- org.awaitility:awaitility:jar:4.2.2:test
[INFO] | +- org.hamcrest:hamcrest:jar:2.2:test
[INFO] | +- org.mockito:mockito-junit-jupiter:jar:5.7.0:test
[INFO] | +- org.skyscreamer:jsonassert:jar:1.5.3:test
[INFO] | | \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
[INFO] | +- org.springframework:spring-core:jar:6.1.13:compile
[INFO] | | \- org.springframework:spring-jcl:jar:6.1.13:compile
[INFO] | +- org.springframework:spring-test:jar:6.1.13:test
[INFO] | \- org.xmlunit:xmlunit-core:jar:2.9.1:test
[INFO] +- org.junit.jupiter:junit-jupiter:jar:5.10.3:test
[INFO] | +- org.junit.jupiter:junit-jupiter-api:jar:5.10.3:test
[INFO] | | +- org.opentest4j:opentest4j:jar:1.3.0:test
[INFO] | | +- org.junit.platform:junit-platform-commons:jar:1.10.3:test
[INFO] | | \- org.apiguardian:apiguardian-api:jar:1.1.2:test
[INFO] | +- org.junit.jupiter:junit-jupiter-params:jar:5.10.3:test
[INFO] | \- org.junit.jupiter:junit-jupiter-engine:jar:5.10.3:test
[INFO] | \- org.junit.platform:junit-platform-engine:jar:1.10.3:test
[INFO] +- com.flextrade.jfixture:jfixture:jar:2.7.2:test
[INFO] +- org.mockito:mockito-core:jar:5.7.0:test
[INFO] | +- net.bytebuddy:byte-buddy:jar:1.14.19:test
[INFO] | +- net.bytebuddy:byte-buddy-agent:jar:1.14.19:test
[INFO] | \- org.objenesis:objenesis:jar:3.3:test
[INFO] +- org.jsoup:jsoup:jar:1.14.3:test
[INFO] +- com.squareup.okhttp3:okhttp:jar:4.12.0:test
[INFO] | \- org.jetbrains.kotlin:kotlin-stdlib-jdk8:jar:1.9.25:test
[INFO] | +- org.jetbrains.kotlin:kotlin-stdlib:jar:1.9.25:test
[INFO] | | \- org.jetbrains:annotations:jar:13.0:test
[INFO] | \- org.jetbrains.kotlin:kotlin-stdlib-jdk7:jar:1.9.25:test
[INFO] +- com.squareup.okhttp3:mockwebserver:jar:4.12.0:test
[INFO] | \- junit:junit:jar:4.13.2:test
[INFO] | \- org.hamcrest:hamcrest-core:jar:2.2:test
[INFO] \- com.squareup.okio:okio:jar:3.4.0:test
[INFO] \- com.squareup.okio:okio-jvm:jar:3.4.0:test
[INFO] \- org.jetbrains.kotlin:kotlin-stdlib-common:jar:1.9.25:test
maven-complier-plugin是这样配置的
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<parameters>true</parameters>
</configuration>
</plugin>
我尝试了这个插件配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>
<arg>-parameters</arg>
<arg>-verbose</arg>
</compilerArgs>
</configuration>
</plugin>
任何帮助将不胜感激。谢谢!
我已经尝试过这个解决方案,但它对我不起作用:https://github.com/spring-projects/spring-boot/issues/38721
我建议你使用这个 mvn 配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
<parameters>true</parameters>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
并且在单元测试中的
@DirtiesContext
处重置 Spring 上下文,以防它已被测试注释修改:
@SpringJUnitConfig
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
class YourUnitTest {