Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 应用程序配置,Bean到xml_Java_Xml_Spring_Javabeans - Fatal编程技术网

Java 应用程序配置,Bean到xml

Java 应用程序配置,Bean到xml,java,xml,spring,javabeans,Java,Xml,Spring,Javabeans,我正在使用基于xml的配置。如何将此java代码转换为xml @Bean public CacheManager cacheManager() { SimpleCacheManager simpleCacheManager = new SimpleCacheManager(); GuavaCache cache1 = new GuavaCache("book", CacheBuilder.newBuilder().build()); GuavaCache cache2 = new Guav

我正在使用基于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代码到xml的表示,我知道我的代码正在进行/尚未完成。您能告诉我将基于java的配置移植到xml的原因吗?我已经有一个关于xml的大型配置(我无法更新),我在Internet上发现了这个示例您可以将基于java的配置与xml结合起来。您需要添加