Spring Cache未创建代理类



我正试图在组件bean上添加缓存,而spring并没有创建代理类。如果我把@Cacheable放在repo上,那么它就可以正常工作。我目前只是通过在每次调用后查看cacheManager内部来验证这一点。我在这里做错了什么??

@Configuration
@EnableCaching
public class CacheConfig {
@Bean
public CacheManager cacheManager() {
return new ConcurrentMapCacheManager("clientids");
}
}
@Service
@RequiredArgsConstructor
public class CacheDelegator {
private final RepoUser getFromRepo;
public ClientReference getId(String email) {
return getFromRepo.getFromRepo(email).orElseThrow(() ->
new ClientNotFoundException(ExceptionType.NOT_FOUND));
}
}
@Component
@RequiredArgsConstructor
public class RepoUser {
private final ClientRepository repository;
@Cacheable("clientids")
Optional<ClientReference> getFromRepo(String email) {
return repository.findClientIdByEmail(email);
}
}
@Repository
public interface ClientRepository extends JpaRepository<ClientReference, Long> {
Optional<ClientReference> findClientIdByEmail(String email);
}

我知道这是一种迂回的方法。不过,我正在努力了解缓存拦截器是如何创建的。

根据上述Deinum。我的方法需要公开。

最新更新