首页 > 解决方案 > "处理程序调度失败;嵌套异常是 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 注释放在服务层而不是服务上,但输出相同。任何指针将不胜感激。谢谢。

标签: spring-bootehcachehibernate-validator

解决方案


我认为你的问题是cacheManager.setTransactionAware(true);。这将导致 Spring 将缓存链接到事务(使用 XA 或它的假版本,我不确定)。因此,如果事务回滚,对缓存的修改也将如此。

但是您当前没有使用 Spring 事务管理器,因为它不在您的类路径中。所以春天不开心。做cacheManager.setTransactionAware(false);应该能解决问题。


推荐阅读