简体   繁体   中英

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

I'm aware of CDI Support; but was wondering what's the correct way of achieving the same in non EE environment with spring. 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?

@Autowired
    private Cache<String, String> cache;

Many Thanks

Spring uses differnet approach for caching - Using Infinispan as a Spring Cache provider .

If you want to inject cache in other way - create cache as bean using some qualifier:

@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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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