我正在使用基于 xml 的配置。我怎样才能将这个java代码翻译成xml?
@Bean
public CacheManager cacheManager() {
SimpleCacheManager simpleCacheManager = new SimpleCacheManager();
GuavaCache cache1 = new GuavaCache("book", CacheBuilder.newBuilder().build());
GuavaCache cache2 = new GuavaCache("books", CacheBuilder.newBuilder()
.expireAfterAccess(30, TimeUnit.MINUTES)
.build());
simpleCacheManager.setCaches(Arrays.asList(cache1, cache2));
return simpleCacheManager;
}
我有这个,但我卡住了:
<bean id="cacheManager" class="org.springframework.cache.guava.GuavaCacheManager">
<property name="caches">
<list>
<ref bean="cache1"/>
<ref bean="cache2"/>
</list>
</property>
</bean>
<bean id="cache1" class="org.springframework.cache.guava.GuavaCache">
<constructor-arg value="book" />
<constructor-arg refer="foo" />
</bean>
<bean id="cahe1Settings" class="com.google.common.cache.CacheBuilder" factory-method="newBuilder">
</bean>
<bean id="foo" factory-bean="cahe1Settings" factory-method="build"/>
最佳答案
试试这个,它对我有用:
<bean id="cacheBuilder" class="com.google.common.cache.CacheBuilder" factory-method="from">
<constructor-arg value="expireAfterAccess=30m" />
</bean>
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
<property name="caches">
<set>
<bean class="org.springframework.cache.guava.GuavaCache">
<constructor-arg value="mycache" />
<constructor-arg>
<bean factory-bean="userCacheBuilder" factory-method="build" />
</constructor-arg>
</bean>
</set>
</property>
</bean>
关于java - 应用程序配置,Bean 到 xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28318462/