reflectionutil错误

cetgtptt  于 2021-07-14  发布在  Java
关注(0)|答案(1)|浏览(339)

我正在尝试在我的存储库层上运行junit测试

@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = {JPAConfig.class, SpringBootMainApplication.class})
public class AddBookTest {

    @Autowired
    private BookRepository bookRepository;

    @Autowired
    private WebApplicationContext wac;

    private MockMvc mockMvc;

    @BeforeEach
    public void setUp() {
        this.mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
    }

    @Test
    @Sql({"/book-schema.sql", "/book-data.sql"})
    void addBook() throws Exception {
        mockMvc.perform(MockMvcRequestBuilders.put("/users/")
                .header("X-MC-CorrelationID", UUID.randomUUID())
                .contentType(MediaType.APPLICATION_JSON_VALUE)
                .accept(MediaType.APPLICATION_JSON)
                .characterEncoding("UTF-8")
                .content("{\"book\": \"LOTR\"}")
                .andExpect(MockMvcResultMatchers.status().isNoContent())
                .andDo(MockMvcResultHandlers.print());
    }

    private String requestBody() {
        return "{\n" +
                "  \"book\": \"LOTR\",\n" +
                "}";
    }

}

我得到以下错误:

java.lang.NoSuchMethodError: 'org.springframework.util.ReflectionUtils$MethodFilter org.springframework.util.ReflectionUtils$MethodFilter.and(org.springframework.util.ReflectionUtils$MethodFilter)'
    at org.springframework.test.context.junit.jupiter.SpringExtension

版本:

implementation group: "org.springframework.boot", name: "spring-boot-starter-web", version: "2.2.1.RELEASE"
implementation group: "org.springframework.boot", name: "spring-boot-starter-data-jpa", version: "2.2.1.RELEASE"
implementation group: "org.springframework.boot", name: "spring-boot-starter-actuator", version: "2.2.1.RELEASE"
testImplementation group: 'org.springframework', name: 'spring-test', version: "5.2.1.RELEASE"
implementation group: 'org.springframework', name: 'spring-context', version: "5.2.1.RELEASE"

简而言之,我的所有spring引导依赖项都在2.2.1.release train上,而spring框架是5.2.1.release。这些版本兼容吗?

yx2lnoni

yx2lnoni1#

很难说清楚发生了什么,但听起来像是类路径上spring版本的冲突。
这个特定的方法“and”非常新,请参见javadoc。它明确指出该方法是从版本“5.3.2”开始的,这是一个非常新的版本。因此,我建议检查测试类路径中jar的依赖树,以了解是否在spring的新版本和旧版本之间进行了混合。

相关问题