代码之家  ›  专栏  ›  技术社区  ›  Vigneshwaran

SpringBoot-GemFire-启动时初始化定位器和端口

  •  0
  • Vigneshwaran  · 技术社区  · 9 年前

    现有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
    
    1 回复  |  直到 9 年前
        1
  •  1
  •   John Blum    9 年前

    @维涅斯瓦兰-

    这个 ClientCacheFactoryBean.setCacheXml(:Resource) native cache.xml resource , 春天 XML配置,因此出现异常。。。

    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” ".

    豆 春天 XML配置元素,来自 Spring beans namespace 当然GemFire是本地人 解析器不知道关于 XML配置和命名空间(例如。 豆

    如果你想使用 春天

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

    干杯 约翰