Skip to content
Advertisement

Lombok generated constructor can not implicit autowire in SpringBootTest

I want to inject class A into class B through the constructor.

Class Structure in test directory

JavaScript
JavaScript

But the following error is thrown when I run the test.

JavaScript

Advertisement

Answer

The problem is already raised in issue#22286, due to difference in autowire handling between Spring and Spring integration with JUnit. Which failed to do implicit autowire on constructor without @Autowired.

So as a workaround, add onConstructor = @__(@Autowired) to @RequiredArgsConstructor to annotate the generated constructor with @Autowired.

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement