После многих попыток я вынужден обратиться за помощью, поскольку @Cacheable не работает. Ниже мой код
import org.apache.catalina.connector.Connector;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableMBeanExport;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jmx.support.RegistrationPolicy;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import com.gym.serviceImpl.CustomRepositoryImpl;
@ComponentScan(basePackages={"com"})
@EntityScan(basePackages={"com"})
@EnableJpaRepositories(basePackages={"com"},repositoryBaseClass = CustomRepositoryImpl.class)
@SpringBootApplication
@EnableAsync
@EnableMBeanExport(registration=RegistrationPolicy.IGNORE_EXISTING)
@EnableCaching
@AutoConfigureBefore(CacheAutoConfiguration.class)
@EnableScheduling
public class VenusApplication extends SpringBootServletInitializer{
@Value("${server.tomcat.ajp.port}")
int ajpPort;
@Value("${server.tomcat.ajp.enabled}")
boolean tomcatAjpEnabled;
public static void main(String[] args) {
SpringApplication.run(VenusApplication.class, args);
}
/*@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(applicationClass);
}
private static Class<VenusApplication> applicationClass = VenusApplication.class;*/
@Bean
public TomcatServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
if (tomcatAjpEnabled)
{
Connector ajpConnector = new Connector("AJP/1.3");
ajpConnector.setPort(ajpPort);
ajpConnector.setSecure(false);
ajpConnector.setAllowTrace(false);
ajpConnector.setScheme("https");
tomcat.addAdditionalTomcatConnectors(ajpConnector);
}
return tomcat;
}
}
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import com.app.jdbc.repo.CommonRepo;
/**
* @author Goku
*
*/
@Service
public class CommonServiceImpl implements CommonService{
@Autowired CommonRepo common;
@Override
@Cacheable(value="access")
public Map<String, Object> getModuleAccess(Integer clientId, Integer userId) {
return common.getModuleAccess(clientId, userId);
}
@CacheEvict(value="access", allEntries=true)
@Scheduled(fixedRate = 300000)
public void evictAllcachesAtIntervals() {
}
}
import org.springframework.cache.CacheManager;
import org.springframework.cache.concurrent.ConcurrentMapCache;
import org.springframework.cache.support.SimpleCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.AuditorAware;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import com.gym.serviceImpl.AuditorAwareImpl;
/**
* @author Goku
*
*/
@Configuration
@EnableJpaAuditing(auditorAwareRef = "auditorAware")
public class JPAConfig {
@Bean
public AuditorAware<String> auditorAware() {
return new AuditorAwareImpl();
}
@Bean
public CacheManager cacheManager() {
// configure and return an implementation of Spring's CacheManager SPI
SimpleCacheManager cacheManager = new SimpleCacheManager();
cacheManager.setCaches(Arrays.asList(new ConcurrentMapCache("access")));
return cacheManager;
}
}
Что не так? любая помощь очень ценится.