繁体   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