简体   繁体   English

如何在Spring非EE应用程序中注入infinispan缓存?

[英]How to Inject infinispan cache in a Spring non EE application?

I'm aware of CDI Support; 我知道CDI支持; but was wondering what's the correct way of achieving the same in non EE environment with spring. 但是我想知道在春季用非EE环境实现相同的正确方法是什么。 We could use weld or inject DefaultCacheManager and get any cache from it, but how to achieve something like below with just spring and JSE? 我们可以使用焊接或注入DefaultCacheManager并从中获取任何缓存,但是如何仅使用spring和JSE来实现如下所示的功能?

@Autowired
    private Cache<String, String> cache;

Many Thanks 非常感谢

Spring uses differnet approach for caching - Using Infinispan as a Spring Cache provider . Spring使用differnet方法进行缓存- 将Infinispan用作Spring Cache提供程序

If you want to inject cache in other way - create cache as bean using some qualifier: 如果要以其他方式注入缓存,请使用一些限定符将缓存作为bean创建:

@Configuration
public class CachesProducer() {
    @Bean(destroyMethod = "methodToCloseCache")
    public Cache<String, String> namesCache() {
        return createInfinispanCacheSomeHow<String, String>();
    }
}

and then 接着

@Named("namesCache")
@Inject
private Cache<String, String>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM