Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring缓存抽象测试_Java_Spring_Memcached_Integration Testing - Fatal编程技术网

Java Spring缓存抽象测试

Java Spring缓存抽象测试,java,spring,memcached,integration-testing,Java,Spring,Memcached,Integration Testing,我在“Spring Cache Abstraction”方面没有太多经验,所以我不确定这是否可行。 我有一个MemcachedConfig类,带有@EnableCaching注释。 我需要从ServiceImpl类测试方法“saveSession”,但我想在测试中嵌入memcached,因此在调用该方法时,请使用测试中定义的方法,而不是applicationContext上的bean。可能吗 @Configuration @EnableCaching public class Memcached

我在“Spring Cache Abstraction”方面没有太多经验,所以我不确定这是否可行。 我有一个MemcachedConfig类,带有@EnableCaching注释。 我需要从ServiceImpl类测试方法“saveSession”,但我想在测试中嵌入memcached,因此在调用该方法时,请使用测试中定义的方法,而不是applicationContext上的bean。可能吗

@Configuration
@EnableCaching
public class MemcachedConfig {
    ....
    @Bean
    public CacheFactory sessionCacheFactory() {
        ....
    }

    @Bean
    public ExtendedSSMCacheManager cacheManager(List<Cache> caches) {
        ....
    }
}

@Service
public class ServiceImpl implements Service {
    ....
    @Autowired
    private ApplicationContext applicationContext;

    private Service proxyOfMe;

    @PostConstruct
    public void initialize()  {
        proxyOfMe = (Service) applicationContext.getBean(Service.class);
    }

    @CachePut(value = VALUE , key = KEY)
        public SessionCache saveSession(String session) {
            ....
    }
    ....
}
@配置
@启用缓存
公共类MemcachedConfig{
....
@豆子
公共缓存工厂sessionCacheFactory(){
....
}
@豆子
公共扩展SSMCacheManager缓存管理器(列出缓存){
....
}
}
@服务
公共类ServiceImpl实现服务{
....
@自动连线
私有应用程序上下文应用程序上下文;
私人服务代理;
@施工后
公共无效初始化(){
proxyOfMe=(服务)applicationContext.getBean(服务.class);
}
@CachePut(值=值,键=键)
公共会话缓存保存会话(字符串会话){
....
}
....
}