In my application I have the following interceptor:
public class AuditInterceptor extends EmptyInterceptor {
adding @Component on the top of the class is working but I am not able to add a service bean from my application since I want to execute some service logic. What I am doing is the following is:
@Slf4j
@Component
public class AuditInterceptor extends EmptyInterceptor {
private final List<Class<?>> updates = new ArrayList<>();
private final List<Class<?>> creates = new ArrayList<>();
private final List<Class<?>> loads = new ArrayList<>();
private final List<Class<?>> deletes = new ArrayList<>();
private final TelemetryClient telemetryClient = new TelemetryClient();
private final PropertyRepository propertyRepository;
public AuditInterceptor(PropertyRepository propertyRepository) {
this.propertyRepository = propertyRepository;
}
and it fails with:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'propertyPartnerRepository' defined in com.microservice.persistence.PropertyPartnerRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Cannot resolve reference to bean 'jpaMappingContext' while setting bean property 'mappingContext'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is org.hibernate.boot.registry.selector.spi.StrategySelectionException: Could not instantiate named strategy class [com.microservice.persistence.AuditInterceptor]
I want to know if there is a way to execute add a service bean in this interceptor so I can execute some service logic?