尝试 Autowire CacheManager 并抛出空指针。本质上,喜欢使用 Spring 的缓存管理器,而实际实现是由 ehcache 实现的。这个想法是将来交换实际的缓存提供程序,以写入spring的接口。所以,这里是配置。
<bean id="cacheMgr" class="org.springframework.cache.ehcache.EhCacheCacheManager">
<property name="cacheManager">
<bean class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="ehcache.xml"/>
<property name="shared" value="true"/>
</bean>
</property>
</bean>
在服务类中,尝试注入。
@Autowired
@Qualifier("cacheMgr")
private org.springframework.cache.CacheManager cacheMgr;
问题是“cacheMgr”变得空了。不确定问题出在哪里。