Lombok Superbuilder Spring Autowire与儿童课程
我有一个父班:
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@SuperBuilder
@Service
public class Parent {}
还有一个子类:
@Profile("integration")
@SuperBuilder
@Service
public class Child extends Parent {}
我仅在这样的集成测试中使用此子类:
@SpringBootTest(
classes = {
...
Child.class,
...
})
@ActiveProfiles({"integration"})
class ITTest {
@Autowired
private Child child;
}
当我尝试运行集成测试时,我在加载应用程序上下文时遇到问题:
通过构造函数参数0表示的不满意的依赖性; 嵌套异常是 org.springframework.beans.factory.nosuchbeandefinitionException:否 合格的豆类 '... service.integration.interfaces.Child $育儿者' 可用:预期至少有1个bean有资格作为Autowire 候选人。依赖项注释:{}
父类在Main,子类中,集成测试正在测试包中。
我该如何解决这个问题?
I have a parent class:
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@SuperBuilder
@Service
public class Parent {}
And a child class:
@Profile("integration")
@SuperBuilder
@Service
public class Child extends Parent {}
I am using this child class only in an integration test like this:
@SpringBootTest(
classes = {
...
Child.class,
...
})
@ActiveProfiles({"integration"})
class ITTest {
@Autowired
private Child child;
}
When I try to run my integration test, I'm having problem on loading application context:
Unsatisfied dependency expressed through constructor parameter 0;
nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No
qualifying bean of type
'...service.integration.interfaces.Child$ChildBuilder'
available: expected at least 1 bean which qualifies as autowire
candidate. Dependency annotations: {}
Parent class is in under main, child class and integration tests are under test package.
How can I solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我解决了这个问题:
我删除了整个@superbuilder并由我自己实现的构造函数。还使用了默认的应用程序上下文,因此从@springboottest上删除了类:
它会自动自动自动化正确的bean。
I have solved the issue:
I removed the whole @SuperBuilder and implemented constructor by myself. Also used default application context, so removed classes from @SpringBootTest:
It automatically autowired the correct bean.