After updating springboot from version 2 to 3.1.4, all the tests are failing because autowired fields(myService) in all my test classes are null. This is throwing null pointer exceptions.
I have a springboot application with a Service class:
@Service
@Slf4j
public class MyService extends MyRepository {
private final AnotherService anotherService;
public MyService(AnotherService anotherService) {
this.anotherService= anotherService;
}
//more functions
}
I’ve written groovy tests for the functions in this class:
@SpringBootTest(classes = Application)
class MyServiceSpec extends Specification {
@Autowired
private MyService myService
def "MyService(test=function1)"() {
// some test code
}
}
I tried solutions posted online like checking annotations, dependencies, etc, but it is not working. How can I make sure the application context loads correctly?
user is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.