Как указано в вопросе ServiceB, мои @Autowired
поля становятся пустыми
@Service
@Component
@ComponentScan({ "com.package" })
@Transactional
public class ServiceA {
@Autowired
private ServiceB serviceB
@PostConstruct
public void init() {
// Calling method in serviceB
serviceB.getService();
}
}
@Service
@Component
@ComponentScan({ "com.package" })
@Transactional
public class ServiceB {
@Autowired
private ServiceC serviceC // Getting null
@Autowired
private ServiceD serviceD // Getting null
@Autowired
private ServiceE serviceE // Getting null
// This method is called from the PostConstruct
getService() {
serviceC.getAnotherService(); // Here getting NPE as serviceC is getting null
}
}
@Service
@Component
@ComponentScan({ "com.package" })
@Transactional
public class ServiceC {
getAnotherService() {
// This method is being not called
}
}
Есть ли способ загрузить все компоненты @Autowired
до @PostConstruct