簡體   English   中英

SpringBoot-GemFire-啟動時初始化定位器和端口

[英]SpringBoot - GemFire - Initialize Locators and port while start up

我正在使用帶有gemfire 8.2的springboot 1.5.2並在xml中配置主機和端口運行良好。 相反,我們對需要從雲服務器配置中讀取的主機和端口的值進行了硬編碼,並且無法讀取xml中的這些值。 計划將主機和端口設置從xml移動到Java代碼。 在啟動時遇到錯誤。

現有的XML配置

<gfe:pool id="clientPool" subscription-enabled="true">
        <gfe:locator host="x.x.x.x" port="x" />
    </gfe:pool> 

在春季啟動時導入此xml。

XML到Java代碼

@Configuration
public class GeodeConfig {

    @Resource
    GemFireCache gemfireCache;

    @Bean
    ClientCacheFactoryBean gemfireCache() {
        ClientCacheFactoryBean gemfireCache = new ClientCacheFactoryBean();

        gemfireCache.setClose(true);
        gemfireCache.setCacheXml(new ClassPathResource("gemfirexml.xml"));
        return gemfireCache;
    }

    @Bean
    PoolFactoryBean gemfirePool(
          @Value("${host}") String host,
          @Value("${port}") int port) {
        PoolFactoryBean gemfirePool = new PoolFactoryBean();
        gemfirePool.setName("clientPool");
        gemfirePool.setSubscriptionEnabled(true);
        gemfirePool.setThreadLocalConnections(false);
        gemfirePool.setServers(Collections.singletonList(new ConnectionEndpoint(host, port)));
        return gemfirePool;
    }


}

例外

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-07-20 12:17:51.486 ERROR [magenta-enterprise-event-testing,,,] 22640 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'geodeConfig': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gemfireCache': FactoryBean threw exception on object creation; nested exception is com.gemstone.gemfire.cache.CacheXmlException: Unknown XML element "beans"
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:321) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264) ~[sprin

@ Vigneshwaran-

ClientCacheFactoryBean.setCacheXml(:Resource)用於設置對GemFire 本機cache.xml資源的引用, 而不是對 Spring XML配置的引用,因此設置為Exception ...

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gemfireCache': FactoryBean threw exception on object creation; nested exception is com.gemstone.gemfire.cache.CacheXmlException: Unknown XML element "beans"

特別是... nested exception is com.gemstone.gemfire.cache.CacheXmlException: Unknown XML element "beans" ,特別是...“ 未知元素'beans' ”。

beans ”顯然是來自Spring beans名稱空間Spring XML配置元素。 當然,GemFire的本機cache.xml解析器對Spring XML配置和名稱空間(例如bean )一無所知。

如果要結合使用Spring XML配置和Spring的JavaConfig,請執行以下操作...

@Configuration
@ImportResource("class/path/to/spring/config.xml")
class GeodeConfig {
 ...
}

干杯,約翰

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM