spring-boot - "处理程序调度失败;嵌套异常是 NoClassDefFoundError: org/springframework/transaction/support/TransactionSynchronizationManager",
问题描述
我是弹簧靴的新手。尝试实现ehcache,但出现以下错误:
Handler dispatch failed; nested exception is NoClassDefFoundError: org/springframework/transaction/support/TransactionSynchronizationManager
什么都没有记录,只有一个 Debug 语句
2018-05-30 14:09:47.291 DEBUG 5520 --- [nio-9091-exec-2] .m.m.a.ExceptionHandlerExceptionResolver : Resolving exception from handler [public org.springframework.http.ResponseEntity<?> com.jetblue.api.controller.AirportLocationController.getAirport(com.jetblue.api.domain.Location,org.springframework.validation.BindingResult)]: org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/transaction/support/TransactionSynchronizationManager
2018-05-30 14:09:47.293 DEBUG 5520 --- [nio-9091-exec-2] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'customizedResponseEntityExceptionHandler'
缓存配置
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
@Configuration
@EnableCaching
public class CacheConfiguration {
@Bean
public EhCacheManagerFactoryBean ehCacheManagerFactory() {
EhCacheManagerFactoryBean cacheManagerFactoryBean = new EhCacheManagerFactoryBean();
cacheManagerFactoryBean.setConfigLocation(new ClassPathResource("ehcache.xml"));
cacheManagerFactoryBean.setShared(true);
return cacheManagerFactoryBean;
}
@Bean
public EhCacheCacheManager ehCacheCacheManager() {
EhCacheCacheManager cacheManager = new EhCacheCacheManager();
cacheManager.setCacheManager(ehCacheManagerFactory().getObject());
cacheManager.setTransactionAware(true);
return cacheManager;
}
}
服务层:
@Override
public NearByAirport getAirport(Location location) {
............
}
界面:
public interface IAirportLocatorService {
/**
* Gets the airport.
*
* @param airport the airport
* @return the airport
*/
@Cacheable(value="nearestAirport", key="#location.latAndLong")
public NearByAirport getAirport(Location location);
}
ehcache.xml
<cache name="nearestAirport" eternal="false"
maxElementsInMemory="250" overflowToDisk="false" diskPersistent="false"
timeToIdleSeconds="21600" timeToLiveSeconds="21600"
memoryStoreEvictionPolicy="LRU" />
我尝试将@Cachable 注释放在服务层而不是服务上,但输出相同。任何指针将不胜感激。谢谢。
解决方案
我认为你的问题是cacheManager.setTransactionAware(true);
。这将导致 Spring 将缓存链接到事务(使用 XA 或它的假版本,我不确定)。因此,如果事务回滚,对缓存的修改也将如此。
但是您当前没有使用 Spring 事务管理器,因为它不在您的类路径中。所以春天不开心。做cacheManager.setTransactionAware(false);
应该能解决问题。
推荐阅读
- postgresql - 无法从 Azure 资源连接到用于 postgres 服务器的 Azure 数据库
- jquery - 网页加载时没有填充谷歌表格
- powershell - Inno Setup - 以变量为参数的编译后批处理文件 - 参数未转换为变量的值
- c# - 使用ninject绑定同一接口的不同实现
- javascript - 在 typescript Excel 插件中使用 webworkers
- c# - Xamarin Forms - 滚动到 ScrollView 顶部的按钮
- docker - 如何使用 docker(分别为 docker-in-docker)在 Gitlab CI 上启动 nginx?
- material-ui - material-ui: AppBar with position="fixed" - 在 iOS 上滚动覆盖带有正文背景的 AppBar
- apache-spark - SPARK Data Frame 中数据的一致视图
- java - Eclipse(或intellij)函数参数使用静态分析