I'm using the latest version of spring and using the caching concept. My (rest) service class seems to not be injected with the caching annotation. If I remove them it works perfectly however I don't use cache which is not what I want.
Application:
@SpringBootApplication
@EnableCaching
public class MyApplication{
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
@Bean
public CacheManager cacheManager() {
SimpleCacheManager cacheManager = new SimpleCacheManager();
cacheManager.setCaches(Arrays.asList(new ConcurrentMapCache("MyCache")));
return cacheManager;
}
The service:
@CacheConfig(cacheNames = "MyCache")
@Service
public class MyServiceImpl implements MyService {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final String errormessage = "Error getting books";
@Autowired
private UserRepositoryCrud userRepository;
public MyServiceImpl () {
}
@Override
@Cacheable(value = "MyCache", key = "#description", unless = "#result?.size() > 0")
public final List<Books> getBooks(String description) {
logger.debug("Starting getBooksService");
//service implementation ...
(I also have a Restcontroler that only call this service) When calling this method getBooks, I got a nullpointer on the logger, but when debugging I realize that everything is null, even the errormessage string... If I remove the @Cacheable annotation, it then works but I do not have the cache working which is not what I want.
Do you know what can be wrong ?
Thanks a lot,