@SpringBootTest会干扰EclipseLink动态编织 [英] @SpringBootTest interferes with EclipseLink dynamic weaving

查看:128
本文介绍了@SpringBootTest会干扰EclipseLink动态编织的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的公司正在使用Spring Boot,Spring MVC,带有EclipseLink和动态编织的JPA开发Web应用程序。
我的任务是准备UI的实现和集成测试,使用JUnit和@SpringBootTest将应用程序分解,并使用Selenium与之交互。

My company is developing a web application using Spring Boot, Spring MVC, JPA with EclipseLink and dynamic weaving. My task is to prepare implementation of UI and integration tests spinning up the application using JUnit and @SpringBootTest and interacting with it using Selenium.

如< a href = https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html rel = nofollow noreferrer> Spring Boot测试功能,使用 @SpringBootApplication 批注的
测试可以利用 @MockBean 批注为bean定义Mockito模拟在ApplicationContext中。
这是通过注册 BeanFactoryPostProcessor MockitoPostProcessor ,递归地扫描带有 @Component 或 @Configuration 用于用 @MockBean 注释的类和字段。

As stated at Spring Boot Testing Features, Tests using the @SpringBootApplication annotation can make use of the @MockBean annotation to define Mockito mocks for beans within the ApplicationContext. This is achieved by registering a BeanFactoryPostProcessor, MockitoPostProcessor, recursively scanning classes annotated with @Component or @Configuration for classes and fields annotated with @MockBean.

不幸的是,这导致这些类中引用的实体类在应该扫描它们的 LocalContainerEntityManagerFactoryBean 之前加载。实例化并使用 LoadTimeWeaver 进行设置,从而导致跳过那些实体的加载时间。
对于执行持久性操作时通过编织类似 _persistence_propertyChange()创建的方法,这会导致 NoSuchMethodException s。

Unfortunately, this causes the entity classes referenced in those classes to be loaded before the LocalContainerEntityManagerFactoryBean that is supposed to scan for them is instantiated and set up with a LoadTimeWeaver, thus causing the load time weaving for those entities to be skipped. This leads to NoSuchMethodExceptions for methods created by weaving like _persistence_propertyChange() when persistence actions are performed.

是否可以将 @SpringBootTest 与EclipseLink和动态编织一起使用?
如果没有,那么为最近的Spring Boot版本设置集成测试
的一个很好的选择是什么?

Is it possible to use @SpringBootTest with EclipseLink and dynamic weaving? If not, what would be a good alternative to set up an integration test for a recent Spring Boot version?

推荐答案

我通过使用自定义 SpringApplicationRunListener contextPrepared()解决了问题, code> ApplicationContext 中的code> BeanFactoryPostProcessor ,然后由Spring执行。

I solved the problem by using a custom SpringApplicationRunListener's contextPrepared() to remove the problematic BeanFactoryPostProcessors from the ApplicationContext before they got executed by Spring.

这篇关于@SpringBootTest会干扰EclipseLink动态编织的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆