Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

java.lang.IllegalStateException: 'cacheResolver' is required

Ao executar ProdutosControllerTest ocorre o erro abaixo. Se eu retiro a anotação @EnableCaching de AppWebConfiguration o teste é executado com sucesso. Alguma ideia de como solucionar?

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheInterceptor' defined in class path resource [org/springframework/cache/annotation/ProxyCachingConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: 'cacheResolver' is required. Either set the cache resolver to use or set the cache manager to create a default cache resolver based on it.
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1568)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:540)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:324)
    at org.springframework.cache.annotation.ProxyCachingConfiguration$$EnhancerBySpringCGLIB$$fb327d46.cacheInterceptor(<generated>)
    at org.springframework.cache.annotation.ProxyCachingConfiguration.cacheAdvisor(ProxyCachingConfiguration.java:46)
    at org.springframework.cache.annotation.ProxyCachingConfiguration$$EnhancerBySpringCGLIB$$fb327d46.CGLIB$cacheAdvisor$1(<generated>)
    at org.springframework.cache.annotation.ProxyCachingConfiguration$$EnhancerBySpringCGLIB$$fb327d46$$FastClassBySpringCGLIB$$5428ebaa.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:312)
    at org.springframework.cache.annotation.ProxyCachingConfiguration$$EnhancerBySpringCGLIB$$fb327d46.cacheAdvisor(<generated>)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:166)
    ... 88 more
Caused by: java.lang.IllegalStateException: 'cacheResolver' is required. Either set the cache resolver to use or set the cache manager to create a default cache resolver based on it.
    at org.springframework.util.Assert.state(Assert.java:385)
    at org.springframework.cache.interceptor.CacheAspectSupport.afterPropertiesSet(CacheAspectSupport.java:169)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1627)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1564)
    ... 107 more
2 respostas
solução!

Encontrei este POST exatamente com o mesmo problema. Realizei todo o curso com o JDK 14, mas este caso específico somente resolvi quando retornei para o JDK 1.8.

https://cursos.alura.com.br/forum/topico-spring-ii-aula-7-produtocontrollertest-java-lang-illegalstateexception-cacheresolver-is-required-57290

Para ter compatibilidade com o JDK 14 você teria que atualizar as dependências do projeto, o próprio Spring teria que ser o 5.2.8