SpringBoot - GemFire - 启动时初始化定位器和端口
SpringBoot - GemFire - Initialize Locators and port while start up
我正在使用 springboot 1.5.2 和 gemfire 8.2,并在 xml 中配置主机和端口运行良好。相反,我们硬编码主机和端口的值需要从云服务器配置中读取,但它无法读取 xml 中的那些值。计划将主机和端口设置从 xml 代码移动到 java 代码。启动时出现以下错误。
现有XML配置
<gfe:pool id="clientPool" subscription-enabled="true">
<gfe:locator host="x.x.x.x" port="x" />
</gfe:pool>
在 spring 启动时导入了这个 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 native cache.xml
resource 的引用,不是 Spring 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'”。
"beans" 显然是 Spring XML 配置元素,来自 Spring beans namespace.当然,GemFire 的原生 cache.xml
解析器对 Spring XML 配置和命名空间一无所知(例如 beans).
如果您想将 Spring XML 配置与 Spring 的 JavaConfig 结合使用,请执行以下操作...
@Configuration
@ImportResource("class/path/to/spring/config.xml")
class GeodeConfig {
...
}
干杯,
约翰
我正在使用 springboot 1.5.2 和 gemfire 8.2,并在 xml 中配置主机和端口运行良好。相反,我们硬编码主机和端口的值需要从云服务器配置中读取,但它无法读取 xml 中的那些值。计划将主机和端口设置从 xml 代码移动到 java 代码。启动时出现以下错误。
现有XML配置
<gfe:pool id="clientPool" subscription-enabled="true">
<gfe:locator host="x.x.x.x" port="x" />
</gfe:pool>
在 spring 启动时导入了这个 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 native cache.xml
resource 的引用,不是 Spring 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'”。
"beans" 显然是 Spring XML 配置元素,来自 Spring beans namespace.当然,GemFire 的原生 cache.xml
解析器对 Spring XML 配置和命名空间一无所知(例如 beans).
如果您想将 Spring XML 配置与 Spring 的 JavaConfig 结合使用,请执行以下操作...
@Configuration
@ImportResource("class/path/to/spring/config.xml")
class GeodeConfig {
...
}
干杯, 约翰