I am new to the spring boot and Bean concept. My Classes are as follow:
public class PersonController {
private final AuditService<Person> auditService;
@GetMapping("/{id}/revisions")
public void getHistory(
@PathVariable String id) {
log.info("Get Audit history for entry with id: {}", id);
List<AuditEntry<Person>> auditEntryList = auditService.getEntityRevisions(id);
log.debug("Profile Audit history for id: {} is : {}", id, auditEntryList);
}
}
@RequiredArgsConstructor
public abstract class AuditBaseService<E> implements AuditService<E> { ... }
I get an error in controller class where I defined the auditService, saying: "Could not autowire. No beans of 'AuditService' type found"`. Then I could fix this by adding a new class who could extend the AuditBaseService as below:
@Service
public class PersonAuditService extends AuditBaseService<Person> {
public PersonAuditService(AuditReader pAudit) {
super(pAudit);
}
}
And the problem could solve. But this is not the good solution because the new class(PersonAuditService) does nothing except calls the superclass.
I would like to add creating bean inside the config file of the project. But I can not do it because I am still confused about bean's creation.
Would be great to get your supports. Thanks
PersonAuditServiceis a class that could be injected intoAuditService<Person> auditService.AuditBaseServiceis an abstract class, you can't donew AuditBaseService(...), you must subclass AuditBaseService.Spring can't create an instance of an abstract class.