I am using springboot 1.5.2 with gemfire 8.2 and configure the host and port in the xml is working good. Instead we hard code the value of host and port need to read from cloud server config and its was not able to read those value in xml. Planned to move the host and port setting from xml to java code. While start up getting below error.
Existing XML configuration
<gfe:pool id="clientPool" subscription-enabled="true">
<gfe:locator host="x.x.x.x" port="x" />
</gfe:pool>
Imported this xml in the spring start up.
XML to Java code
@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;
}
}
Exception
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-
The ClientCacheFactoryBean.setCacheXml(:Resource)
is for setting a reference to a GemFire native cache.xml
resource, not Spring XML config, hence the 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"
In particular... nested exception is com.gemstone.gemfire.cache.CacheXmlException: Unknown XML element "beans"
and specifically... "Unknown element 'beans'".
"beans" is clearly a Spring XML config element, from the Spring beans namespace. Of course GemFire's native cache.xml
parser does not know anything about Spring XML config and namespaces (e.g. beans).
If you want to use Spring XML config in conjunction with Spring's JavaConfig, then do the following...
@Configuration
@ImportResource("class/path/to/spring/config.xml")
class GeodeConfig {
...
}
Cheers, John