I have a Service class , in below code, after the bean is instantiated by Spring, the ‘getRepositoryInstance’ method is automatically invoked.
Inside this method, it retrieves an instance of a repository service from a factory object and assigns it to the identityRepoService variable.
In RepoService class, which has createRecord method which is calling createMapper() from Mapper class.
In Mapper class, I have to use repoService again to the get the records.
In Mapper class should I use the same postConstruct code that is in Service class?
But, when I use the same postConstruct code in Mapper class, getting null pointer for repoService.
class Service {
@Autowired
private RepoFactory factory;
private RepoService repoService;
@PostConstruct
public void getRepositoryInstance() {
repoService = factory.getRepositoryService();
}
public void create() {
repoService.createRecord();
}
}
@Service
@Qualifier("repoService")
class RepoService {
@Autowired
private mapper;
createRecord(){
mapper.createMapper();
}
@Component
class Mapper {
createMapper(){
repoService.getRecord();
}
} ```