gpt4 book ai didi

java - 应用程序配置,Bean 到 xml

转载 作者:太空宇宙 更新时间:2023-11-04 06:14:06 24 4
gpt4 key购买 nike

我正在使用基于 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com