spring - 无法代理接口实现方法 [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 创建一个代理?我如何(或应该)解决此警告?
解决方案
推荐阅读
- firebase - 如何根据 Flutter 中 FutureBuilder 中另一个 firebase 查询的值从 firebase 查询中获取数据?
- pine-script - Pine Script 使用以前的 RSI 交叉点作为新交叉点的参考
- c - 使用 AVX2 查找元素索引 - 代码优化
- c# - 如何在 C# GUI 中搜索 Excel 工作表?
- java - 如何使用 Like 、between 和 enum 编写 jpa 查询?
- flutter - 从多行中退出焦点 - Flutter
- javascript - 我按标签对视频进行排序的脚本根本不起作用
- android - 网格布局+卡片不显示图像
- php - PHP:基于 POST / GET 用户输入加载内容
- pytorch - 在 Pytorch 中训练 1D CNN