首页 > 解决方案 > 无法代理接口实现方法 [public final void AbstractTestNGSpringContextTests.setApplicationContext()]

问题描述

我有一个 spring 数据测试类(使用 TestNG)来测试我的 spring 数据存储库。我在测试开始后刚刚遇到这个警告/信息消息,想知道这是否需要修复?

2018-08-06 15:30:07.932 WARN 8028 --- [main] osaop.framework.CglibAopProxy:无法代理接口实现方法 [public final void org.springframework.test.context.testng.AbstractTestNGSpringContextTests.setApplicationContext(org .springframework.context.ApplicationContext)] 因为它被标记为 final:考虑使用基于接口的 JDK 代理!

2018-08-06 15:30:07.934 INFO 8028 --- [main] osaop.framework.CglibAopProxy:最终方法 [public final void org.springframework.test.context.testng.AbstractTestNGSpringContextTests.setApplicationContext(org.springframework.context. ApplicationContext)] 无法通过 CGLIB 代理:对此方法的调用将不会路由到目标实例,并且可能会导致针对代理实例中未初始化字段的 NPE。

对于代码完整性,这里是我的测试基类:

@DataJpaTest
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@ContextConfiguration(classes = {RepositoryConfig.class, TestConfig.class})
@TestPropertySource(properties = {"spring.jpa.properties.hibernate.format_sql=true", "spring.jpa.properties.hibernate.show_sql=true"})
public class AbstractRespositoryTest extends AbstractTestNGSpringContextTests {

}

Spring 为什么要围绕 AbstractTestNGSpringContextTests 创建一个代理?我如何(或应该)解决此警告?

标签: springtestngcglib

解决方案


推荐阅读