Spring-Data-Gemfire - Unable to contact a Locator service. Operation either timed out or Locator does not exist - spring-boot

I want to connect to a exist locator.
Now I don't have client-server.
I started a locator,port is 40001, server1 port is 40411.
gfsh>list members
Name | Id
------- | ----------------------------------------------
test1 | 192.168.1.106(test1:1880:locator):1024
server1 | 192.168.1.106(server1:7532):1025
Configuration is:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:gfe-data="http://www.springframework.org/schema/data/gemfire"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gfe="http://www.springframework.org/schema/gemfire"
xmlns:repository="http://www.springframework.org/schema/data/repository"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/data/gemfire http://www.springframework.org/schema/data/gemfire/spring-data-gemfire.xsd
http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/data/repository/spring-repository.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<util:properties id="gemfireProperties">
<prop key="locators">localhost[40001]
<prop key="mcast-port">0
</util:properties>
<gfe:cache properties-ref="gemfireProperties"/>
<gfe:cache-server port="40411" />
<bean id="portGenerator" class="com.demo.server.ServerPortGenerator" />
<gfe:replicated-region id="Person"/>
</beans>
Error is :
[info 2017/07/04 23:48:12.546 CST tid=0x1] Defaulting license-working-dir to current working directory "C:\Users\IBM_ADMIN\Documents\Workspace - Shirley\Workspace_SpringBoot\demo".
[info 2017/07/04 23:48:12.547 CST tid=0x1] Licensing required 2 milliseconds.
[info 2017/07/04 23:48:12.923 CST tid=0x1] GemFire P2P Listener started on tcp:///192.168.1.106:53073
[info 2017/07/04 23:48:13.094 CST tid=0x20] unable to connect to locator localhost(null):40001
2017-07-04 23:48:16.200 WARN 10904 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gemfireServer': Cannot resolve reference to bean 'gemfireCache' while setting bean property 'cache'; 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.GemFireConfigException: Unable to contact a Locator service. Operation either timed out or Locator does not exist. Configured list of locators is "[localhost(null):40001]".
2017-07-04 23:48:16.200 WARN 10904 --- [ main] o.s.b.f.support.DisposableBeanAdapter : Invocation of destroy method failed on bean with name 'gemfireCache': com.gemstone.gemfire.cache.CacheClosedException: A cache has not yet been created.
2017-07-04 23:48:16.219 ERROR 10904 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gemfireServer': Cannot resolve reference to bean 'gemfireCache' while setting bean property 'cache'; 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.GemFireConfigException: Unable to contact a Locator service. Operation either timed out or Locator does not exist. Configured list of locators is "[localhost(null):40001]".
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1531) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1276) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:742) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) ~[spring-boot-1.5.4.RELEASE.jar:1.5.4.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) ~[spring-boot-1.5.4.RELEASE.jar:1.5.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) ~[spring-boot-1.5.4.RELEASE.jar:1.5.4.RELEASE]
at com.demo.server.ServerApplication.main(ServerApplication.java:32) [classes/:na]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gemfireCache': FactoryBean threw exception on object creation; nested exception is com.gemstone.gemfire.GemFireConfigException: Unable to contact a Locator service. Operation either timed out or Locator does not exist. Configured list of locators is "[localhost(null):40001]".
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:175) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:103) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1634) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:254) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
... 16 common frames omitted
Caused by: com.gemstone.gemfire.GemFireConfigException: Unable to contact a Locator service. Operation either timed out or Locator does not exist. Configured list of locators is "[localhost(null):40001]".
at com.gemstone.org.jgroups.protocols.TCPGOSSIP.sendGetMembersRequest(TCPGOSSIP.java:222) ~[gemfire-8.2.4.jar:na]
at com.gemstone.org.jgroups.protocols.PingSender.run(PingSender.java:85) ~[gemfire-8.2.4.jar:na]
at java.lang.Thread.run(Unknown Source) ~[na:1.8.0_111]
Oh my god, I have no idea for this problem.
Anyone who can help me ?
I just want to build a client-server system.
But now I even couldn't to set-up the server.
Update on July.09 - 2017
Hello John, I tried your example, but I still met error.
First, I use gfsh to start a locator.
C:\Users\IBM_ADMIN>gfsh
_________________________ __
/ _____/ ______/ ______/ /____/ /
/ / __/ /___ /_____ / _____ /
/ /__/ / ____/ _____/ / / / /
/______/_/ /______/_/ /_/ 9.0.4
Monitor and Manage Pivotal GemFire
gfsh>start locator --name=GemFireLocator --log-level=config
Starting a Geode Locator in C:\Users\IBM_ADMIN\GemFireLocator...
......
Locator in C:\Users\IBM_ADMIN\GemFireLocator on ADMINIB-CI3Q48M[10334] as GemFireLocator is currently online.
Process ID: 7256
Uptime: 8 seconds
GemFire Version: 9.0.4
Java Version: 1.8.0_101
Log File: C:\Users\IBM_ADMIN\GemFireLocator\GemFireLocator.log
JVM Arguments: -Dgemfire.enable-cluster-configuration=true -Dgemfire.load-cluster-configuration-from-dir=false -Dgemfire
.log-level=config -Dgemfire.launcher.registerSignalHandlers=true -Djava.awt.headless=true -Dsun.rmi.dgc.server.gcInterva
l=9223372036854775806
Class-Path: C:\Program Files\Java\pivotal-gemfire-9.0.4\lib\geode-core-9.0.4.jar;C:\Program Files\Java\pivotal-gemfire-9
.0.4\lib\geode-dependencies.jar
Successfully connected to: JMX Manager [host=ADMINIB-CI3Q48M, port=1099]
gfsh>list members
Name | Id
-------------- | -------------------------------------------------------
GemFireLocator | 192.168.1.106(GemFireLocator:7256:locator):1024
gfsh>describe member --name=GemFireLocator
Name : GemFireLocator
Id : 192.168.1.106(GemFireLocator:7256:locator):1024
Host : ADMINIB-CI3Q48M
Regions :
PID : 7256
Groups :
Used Heap : 90M
Max Heap : 1755M
Working Dir : C:\Users\IBM_ADMIN\GemFireLocator
Log file : C:\Users\IBM_ADMIN\GemFireLocator\GemFireLocator.log
Locators : 192.168.1.106[10334]
And then as you mentioned in the spring-boot-gemfire-server-example, I tried to run $gradlew bootRun.
But the error shows:
Caused by: java.net.BindException: Address already in use: JVM_Bind
[info 2017/07/09 14:57:24.270 CST tid=0x1] Defaulting license-working-dir to current working directory "C:\Users
IBM_ADMIN\Documents\Workspace - Shirley\Workspace_SpringBoot\spring-boot-gemfire-server-example".
[info 2017/07/09 14:57:24.273 CST tid=0x1] Licensing required 4 milliseconds.
[info 2017/07/09 14:57:24.324 CST tid=0x1] Starting peer location for Distribution Locator on localhost/127.0.0.
[10334]
[info 2017/07/09 14:57:24.333 CST tid=0x1] Starting Distribution Locator on localhost/127.0.0.1[10334]
[info 2017/07/09 14:57:24.347 CST tid=0x1] Distribution Locator on localhost/127.0.0.1[10334] is stopped
[main] WARN org.springframework.context.annotation.AnnotationConfigApplicationContext - Exception encountered during co
text initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Err
r creating bean with name 'gemfireCacheServer' defined in org.example.SpringBootGemFireServer: Unsatisfied dependency e
pressed through method 'gemfireCacheServer' parameter 0; nested exception is org.springframework.beans.factory.BeanCrea
ionException: Error creating bean with name 'gemfireCache': FactoryBean threw exception on object creation; nested exce
tion is com.gemstone.gemfire.GemFireIOException: Problem starting a locator service
[main] WARN org.springframework.beans.factory.support.DisposableBeanAdapter - Invocation of destroy method failed on be
n with name 'gemfireCache': com.gemstone.gemfire.cache.CacheClosedException: A cache has not yet been created.
[main] INFO org.springframework.boot.autoconfigure.logging.AutoConfigurationReportLoggingInitializer -
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enable
.
[main] ERROR org.springframework.boot.SpringApplication - Application startup failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'gemfireCacheServer' de
ined in org.example.SpringBootGemFireServer: Unsatisfied dependency expressed through method 'gemfireCacheServer' param
ter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gemf
reCache': FactoryBean threw exception on object creation; nested exception is com.gemstone.gemfire.GemFireIOException:
roblem starting a locator service
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:7
9)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResol
er.java:467)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(A
stractAutowireCapableBeanFactory.java:1128)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAuto
ireCapableBeanFactory.java:1022)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCa
ableBeanFactory.java:512)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapa
leBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.suefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.ja
a:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListabl
BeanFactory.java:735)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractAppli
ationContext.java:866)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175)
at org.example.SpringBootGemFireServer.main(SpringBootGemFireServer.java:52)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gemfireCache': Facto
yBean threw exception on object creation; nested exception is com.gemstone.gemfire.GemFireIOException: Problem starting
a locator service
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanR
gistrySupport.java:175)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanReg
strySupport.java:103)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.j
va:1606)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:317)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
rg.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:207)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBean
actory.java:1131)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFa
tory.java:1059)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.j
va:835)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:7
1)
... 18 more
Caused by: com.gemstone.gemfire.GemFireIOException: Problem starting a locator service
at com.gemstone.gemfire.distributed.internal.InternalDistributedSystem.startInitLocator(InternalDistributedSyst
m.java:847)
at com.gemstone.gemfire.distributed.internal.InternalDistributedSystem.initialize(InternalDistributedSystem.jav
:606)
at com.gemstone.gemfire.distributed.internal.InternalDistributedSystem.newInstance(InternalDistributedSystem.ja
a:281)
at com.gemstone.gemfire.distributed.DistributedSystem.connect(DistributedSystem.java:1651)
at com.gemstone.gemfire.cache.CacheFactory.create(CacheFactory.java:227)
at org.springframework.data.gemfire.CacheFactoryBean.createCache(CacheFactoryBean.java:356)
at org.springframework.data.gemfire.CacheFactoryBean.resolveCache(CacheFactoryBean.java:250)
at org.springframework.data.gemfire.CacheFactoryBean.init(CacheFactoryBean.java:191)
at org.springframework.data.gemfire.CacheFactoryBean.getObject(CacheFactoryBean.java:178)
at org.springframework.data.gemfire.CacheFactoryBean.getObject(CacheFactoryBean.java:88)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanR
gistrySupport.java:168)
... 27 more
Caused by: java.net.BindException: Failed to create server socket on localhost/127.0.0.1[10,334]
at com.gemstone.gemfire.internal.SocketCreator.createServerSocket(SocketCreator.java:829)
at com.gemstone.gemfire.internal.SocketCreator.createServerSocket(SocketCreator.java:789)
at com.gemstone.org.jgroups.stack.tcpserver.TcpServer.startServerThread(TcpServer.java:179)
at com.gemstone.org.jgroups.stack.tcpserver.TcpServer.start(TcpServer.java:168)
at com.gemstone.gemfire.distributed.internal.InternalLocator.startTcpServer(InternalLocator.java:629)
at com.gemstone.gemfire.distributed.internal.InternalLocator.startPeerLocation(InternalLocator.java:698)
at com.gemstone.gemfire.distributed.internal.InternalDistributedSystem.startInitLocator(InternalDistributedSyst
m.java:832)
... 37 more
Caused by: java.net.BindException: Address already in use: JVM_Bind
at java.net.DualStackPlainSocketImpl.bind0(Native Method)
at java.net.DualStackPlainSocketImpl.socketBind(DualStackPlainSocketImpl.java:106)
at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:387)
at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:190)
at java.net.ServerSocket.bind(ServerSocket.java:375)
at com.gemstone.gemfire.internal.SocketCreator.createServerSocket(SocketCreator.java:826)
... 43 more
:bootRun FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':bootRun'.
> Process 'command 'C:\Program Files\Java\jdk1.8.0_101\bin\java.exe'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 14.9 secs
And then, I used gfsh to stopped the locator.
I tried to run your example directly ( without start a locator first ).
Unbelievable, it succeed.
It seems like that your example is to start a new Gemfire locator and a server, not connect to a exist locator.
[info 2017/07/09 15:19:16.930 CST tid=0x1] Defaulting license-working-dir to current working directory "C:\Users\
IBM_ADMIN\Documents\Workspace - Shirley\Workspace_SpringBoot\spring-boot-gemfire-server-example".
[info 2017/07/09 15:19:16.935 CST tid=0x1] Licensing required 7 milliseconds.
[info 2017/07/09 15:19:17.000 CST tid=0x1] Starting peer location for Distribution Locator on localhost/127.0.0.1
[10334]
[info 2017/07/09 15:19:17.016 CST tid=0x1] Starting Distribution Locator on localhost/127.0.0.1[10334]
[info 2017/07/09 15:19:18.376 CST tid=0x1] GemFire P2P Listener started on tcp:///192.168.1.106:45643
[info 2017/07/09 15:19:18.624 CST tid=0x22] locator localhost(null):10334 member address is ADMINIB-CI3
Q48M(SpringBootGemFireServer):37651
[info 2017/07/09 15:19:25.674 CST tid=0x25] locator localhost(null):10334 member address is ADMINIB-CI3
Q48M(SpringBootGemFireServer):37651
[info 2017/07/09 15:19:30.686 CST tid=0x1] Membership: lead member is now ADMINIB-CI3Q48M(SpringBootGemFireServer
):37651
[info 2017/07/09 15:19:30.701 CST tid=0x1] This member, ADMINIB-CI3Q48M(SpringBootGemFireServer):37651, is becomi
ng group coordinator.
[info 2017/07/09 15:19:30.710 CST tid=0x1] Entered into membership with ID ADMINIB-CI3Q48M(SpringBootGemFireServe
r):37651.
[info 2017/07/09 15:19:30.712 CST tid=0x1] Starting DistributionManager ADMINIB-CI3Q48M(SpringBootGemFireServer):37651. (took 12629/ ms)
[info 2017/07/09 15:19:30.715 CST tid=0x1] Initial (membershipManager) view = [ADMINIB-CI3Q48M(SpringBootGemFire
Server):37651{lead}]
[info 2017/07/09 15:19:30.715 CST tid=0x1] Admitting member :37651>.
Now there are 1 non-admin member(s).
[info 2017/07/09 15:19:30.716 CST tid=0x1] ADMINIB-CI3Q48M(SpringBootGemFireServer):37651 is the elder and th
e only member.
[info 2017/07/09 15:19:31.081 CST tid=0x1] Did not hear back from any other system. I am the first one.
[info 2017/07/09 15:19:31.086 CST tid=0x1] Starting server location for Distribution Locator on localhost/127.0.0
.1[10334]
[info 2017/07/09 15:19:31.358 CST tid=0x1] Initializing region _monitoringRegion_192.168.1.10637651
[info 2017/07/09 15:19:31.364 CST tid=0x1] Initialization of region _monitoringRegion_192.168.1.10637651 comp
leted
[info 2017/07/09 15:19:32.857 CST tid=0x1] Initializing region PdxTypes
[info 2017/07/09 15:19:32.857 CST tid=0x1] Initialization of region PdxTypes completed
[main] INFO org.springframework.data.gemfire.CacheFactoryBean - Connected to Distributed System [SpringBootGemFireServer
] as Member [ADMINIB-CI3Q48M(SpringBootGemFireServer):37651]in Group(s) [[]] with Role(s) [[]] on Host [ADMINIB-CI3Q
48M] having PID [0].
[main] INFO org.springframework.data.gemfire.CacheFactoryBean - Created new GemFire v.8.2.0 Cache [SpringBootGemFireServ
er].
[info 2017/07/09 15:19:32.935 CST tid=0x1] Initializing region __PR
[info 2017/07/09 15:19:32.935 CST tid=0x1] Initialization of region __PR completed
[info 2017/07/09 15:19:32.986 CST tid=0x1] Partitioned Region /Factorials is born with prId=1 ident:#Factorials
[main] INFO org.springframework.data.gemfire.PartitionedRegionFactoryBean - Created new Cache Region [Factorials].
[main] INFO org.springframework.jmx.export.annotation.AnnotationMBeanExporter - Registering beans for JMX exposure on st
artup
[main] INFO org.springframework.context.support.DefaultLifecycleProcessor - Starting beans in phase 2147483647
[info 2017/07/09 15:19:33.379 CST tid=0x1] Bridge server connection listener bound to address localhost/127.0.0.1
:40404 with backlog 1,000.
[info 2017/07/09 15:19:33.396 CST tid=0x1] ClientHealthMonitorThread maximum allowed time between pings: 15,000
[info 2017/07/09 15:19:33.425 CST tid=0x1] CacheServer Configuration: port=40404 max-connections=800 max-thread
s=0 notify-by-subscription=true socket-buffer-size=32768 maximum-time-between-pings=15000 maximum-message-count=230000 m
essage-time-to-live=180 eviction-policy=none capacity=1 overflow directory=. groups=[] loadProbe=ConnectionCountProbe lo
adPollInterval=5000 tcpNoDelay=true
[main] INFO org.example.SpringBootGemFireServer - Started SpringBootGemFireServer in 20.399 seconds (JVM running for 20.
823)
[info 2017/07/09 15:21:15.585 CST tid=0x3e] (tid=62 msgId=0) Executing list member
s
[info 2017/07/09 15:22:26.546 CST tid=0x3e] (tid=62 msgId=1) Executing describe me
mber --name GemFireLocator
> Building 80% > :bootRun
And I can use gfsh to connect to the locator what your example code created.
gfsh>
gfsh>stop locator --name GemFireLocator
Stopping Locator running in C:\Users\IBM_ADMIN\GemFireLocator on ADMINIB-CI3Q48M[10334] as GemFireLocator...
Process ID: 7256
Log File: C:\Users\IBM_ADMIN\GemFireLocator\GemFireLocator.log
....
No longer connected to ADMINIB-CI3Q48M[1099].
gfsh>gfsh>list members
"list members" is not available. Reason: Requires connection.
gfsh>connect to loaclhost[10334]
Connecting to Locator at [host=localhost, port=10334] ..
Connecting to Manager at [host=ADMINIB-CI3Q48M, port=1199] ..
Successfully connected to: [host=ADMINIB-CI3Q48M, port=1199]
gfsh>list members
Member Count : 1
Coordinator : SpringBootGemFireServer (ADMINIB-CI3Q48M(SpringBootGemFireServer):37651)
Name | Id
----------------------- | --------------------------------------------------
SpringBootGemFireServer | ADMINIB-CI3Q48M(SpringBootGemFireServer):37651
gfsh>describe member --name=SpringBootGemFireServer
Name : SpringBootGemFireServer
Id : ADMINIB-CI3Q48M(SpringBootGemFireServer):37651
Host : ADMINIB-CI3Q48M
Regions : Factorials
PID : 0
Groups :
Used Heap : 117M
Max Heap : 1755M
Working Dir : C:\Users\IBM_ADMIN\Documents\Workspace - Shirley\Workspace_SpringBoot\spring-boot-gemfire-server-example
Log file : C:\Users\IBM_ADMIN\Documents\Workspace - Shirley\Workspace_SpringBoot\spring-boot-gemfire-server-example
Locators : localhost[10334]
Cache Server Information
Server Bind : localhost
Server Port : 40404
Running : true
Client Connections : 0
gfsh>list regions
List of regions
---------------
Factorials
gfsh>describe region --name=/Factorials
..........................................................
Name : Factorials
Data Policy : partition
Hosting Members : SpringBootGemFireServer
Non-Default Attributes Shared By Hosting Members
Type | Name | Value
------ | ---- | -----
Region | size | 0
Could you plese help to check it ?

Well, the Stack Trace is pretty revealing in this case.
Essentially, the Spring container was unable to create an instance of a GemFire "peer" cache (which is based on the <gfe:cache> element in your Spring XML config) because GemFire was unable to find the Locator you started from Gfsh...
Caused by: com.gemstone.gemfire.GemFireConfigException: Unable to contact a Locator service. Operation either timed out or Locator does not exist. Configured list of locators is "[localhost(null):40001]".
at com.gemstone.org.jgroups.protocols.TCPGOSSIP.sendGetMembersRequest(TCPGOSSIP.java:222) ~[gemfire-8.2.4.jar:na]
at com.gemstone.org.jgroups.protocols.PingSender.run(PingSender.java:85) ~[gemfire-8.2.4.jar:na]
at java.lang.Thread.run(Unknown Source) ~[na:1.8.0_111]
Hence...
c.g.g.GemFireConfigException: Unable to contact a Locator service. Operation either timed out or Locator does not exist.
It goes on to state that...
Configured list of locators is "[localhost(null):40001]".
The locators property in your gemfireProperties bean definition (which defines the "GemFire properties") is what a pending GemFire peer looking to join a cluster uses to find the GemFire Locator (and by extension, the cluster to join). Indeed, 1 or more Locator endpoints (e.g. host1[port1],host2[port2],...,hostN[portN]) defines the cluster to which the pending peer member will join.
Outside of your malformed XML for the gemfireProperties bean definition in your Spring XML config, the value of the locators property appears to be correct. You have a "Locator" running locally, listening on port 40001, at least according to your statements. That is NOT apparent from the list members command, though.
So...
Fist, I assume "test1" is your Locator?
And, you started your Locator using... gfsh> start locator --name=tests1 --port=40001 ... (I also suggest turning up the log level with --log-level=config)
Finally, I assume "server1" is indeed a "GemFire Server"?
If "'test1" is indeed your Locator, then you can get the runtime information for the Locator usingstatus locator`, for instance...
gfsh>status locator --name=test1
Locator in /Users/jblum/pivdev/lab/test1 on 10.99.199.10[40001] as test1 is currently online.
Process ID: 89632
Uptime: 1 minute 15 seconds
GemFire Version: 9.0.4
Java Version: 1.8.0_121
Log File: /Users/jblum/pivdev/lab/test1/test1.log
JVM Arguments: -Dgemfire.enable-cluster-configuration=true -Dgemfire.load-cluster-configuration-from-dir=false -Dgemfire.log-level=config -Dgemfire.launcher.registerSignalHandlers=true -Djava.awt.headless=true -Dsun.rmi.dgc.server.gcInterval=9223372036854775806
Class-Path: /Users/jblum/Downloads/Pivotal/GemStone/Products/PivotalGemFire/pivotal-gemfire-9.0.4/lib/geode-core-9.0.4.jar:/Users/jblum/Downloads/Pivotal/GemStone/Products/PivotalGemFire/pivotal-gemfire-9.0.4/lib/geode-dependencies.jar
Cluster configuration service is up and running.
Now, I have a project, complete with documentation/instructions, you can use to connect a GemFire CacheServer, peer cache application configured with Spring (Data GemFire) and bootstrapped with Spring Boot, available here.
My "tests1" Locator is already running, as shown above with the status locator --name=test1 Gfsh command. If I list members before starting my Spring Boot GemFire peer cache, CacheServer application, you see this...
gfsh>list members
Name | Id
----- | ----------------------------------------------
test1 | 10.99.199.10(test1:89632:locator)<ec><v0>:1024
Then, when I start my embedded server, you see this...
gfsh>list members
Name | Id
----------------------- | --------------------------------------------------------
test1 | 10.99.199.10(test1:89632:locator)<ec><v0>:1024
SpringBootGemFireServer | 10.99.199.10(SpringBootGemFireServer:89790)<ec><v1>:1025
NOTE: I ran the server from inside my IDE (IntelliJ IDEA). Of course, it would work from the command-line too.
NOTE: Since the Locator is NOT running on the default port (i.e. 10334), it is running on 40001, you need to set the custom, application spring.gemfire.locators JVM System property before running the server, to "localhost[40001]". This property translates into GemFire's locators property here and here.
Because list members shows both GemFire processes (Locator + Server), you know that the Server has joined the cluster based on the Locator.
Again, feel free to refer to my example.
Hope this helps!
-John

Ok, first, when you started the GemFire Locator (i.e. "GemFireLocator" using Gfsh), you used the following Gfsh command...
gfsh> start locator --name=GemFireLocator --log-level=config
This resulted in starting the Locator on the default port, 10334, which is not the port you stated previously, 40001, but that is fine; it is easier to run the sample this way.
This is also apparent from the describe member command...
gfsh>describe member --name=GemFireLocator
Which resulted in...
Name : GemFireLocator
Id : 192.168.1.106(GemFireLocator:7256:locator):1024
Host : ADMINIB-CI3Q48M
Regions :
PID : 7256
Groups :
Used Heap : 90M
Max Heap : 1755M
Working Dir : C:\Users\IBM_ADMIN\GemFireLocator
Log file : C:\Users\IBM_ADMIN\GemFireLocator\GemFireLocator.log
Locators : 192.168.1.106[10334]
The last line...
Locators : 192.168.1.106[10334]
... reveals that the Locator is listening on port 10334 bound to address 192.168.1.106.
Then, you proceed in starting the GemFire Server using my sample. I suspect not only did you run $ gradlew bootRun from the command-line, but that you followed the instructions to conclusion, including "Running with an Embedded GemFire/Geode Locator"... yes?
It is actually apparent from the new Stack Trace you posted...
...
...
Caused by: java.net.BindException: Failed to create server socket on localhost/127.0.0.1[10,334]
at com.gemstone.gemfire.internal.SocketCreator.createServerSocket(SocketCreator.java:829)
at com.gemstone.gemfire.internal.SocketCreator.createServerSocket(SocketCreator.java:789)
at com.gemstone.org.jgroups.stack.tcpserver.TcpServer.startServerThread(TcpServer.java:179)
at com.gemstone.org.jgroups.stack.tcpserver.TcpServer.start(TcpServer.java:168)
at com.gemstone.gemfire.distributed.internal.InternalLocator.startTcpServer(InternalLocator.java:629)
at com.gemstone.gemfire.distributed.internal.InternalLocator.startPeerLocation(InternalLocator.java:698)
at com.gemstone.gemfire.distributed.internal.InternalDistributedSystem.startInitLocator(InternalDistributedSyst
m.java:832)
... 37 more
Caused by: java.net.BindException: Address already in use: JVM_Bind
at java.net.DualStackPlainSocketImpl.bind0(Native Method)
at java.net.DualStackPlainSocketImpl.socketBind(DualStackPlainSocketImpl.java:106)
at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:387)
at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:190)
at java.net.ServerSocket.bind(ServerSocket.java:375)
at com.gemstone.gemfire.internal.SocketCreator.createServerSocket(SocketCreator.java:826)
... 43 more
Hence...
Caused by: java.net.BindException: Failed to create server socket on localhost/127.0.0.1[10,334]
And...
Caused by: java.net.BindException: Address already in use: JVM_Bind
Do not confuse "creating a server socket" with starting a GemFire Server. In Java (as you may already know), whenever you bind an address/port for a "client" application to connect, you use a java.net.ServerSocket.
In this case, a Locator is a "server" and creates a java.net.ServerSocket for any clients (e.g. Gfsh, or other peer members like GemFire (Cache) Servers) that want to connect to the GemFire "cluster" defined by the Locator.
And, as you can see when you stopped the first Locator ("GemFireLocator") you started in Gfsh initially, and then ran the sample by itself (and it started successfully!), when you "described" the member, using...
gfsh> describe member --name=SpringBootGemFireServer
Name | Id
----------------------- | --------------------------------------------------
SpringBootGemFireServer | ADMINIB-CI3Q48M(SpringBootGemFireServer):37651
gfsh>describe member --name=SpringBootGemFireServer
Name : SpringBootGemFireServer
Id : ADMINIB-CI3Q48M(SpringBootGemFireServer):37651
Host : ADMINIB-CI3Q48M
Regions : Factorials
PID : 0
Groups :
Used Heap : 117M
Max Heap : 1755M
Working Dir : C:\Users\IBM_ADMIN\Documents\Workspace - Shirley\Workspace_SpringBoot\spring-boot-gemfire-server-example
Log file : C:\Users\IBM_ADMIN\Documents\Workspace - Shirley\Workspace_SpringBoot\spring-boot-gemfire-server-example
Locators : localhost[10334]
Cache Server Information
Server Bind : localhost
Server Port : 40404
Running : true
Client Connections : 0
You can see several bits of interesting information from the describe member command.
First, and most importantly, you see...
Locators : localhost[10334]
This is the "embedded" Locator. It is listening on port 10334, which is why you encountered the j.n.BindException when your "GemFireLocator" was running the first time.
This means the spring.gemfire.start-locator application property was set, and by default, I see that it is. This in turn sets the GemFire property, start-locator (from the application property), which then causes GemFire to start an "embedded" Locator.
As result, this causes a port conflict when "GemFireLocator" is running since you started the "GemFireLocator" on the default port, 10334.
If you had started the "GemFireLocator" or the "embedded" Locator on a different port, you would not have had this problem.
You can start a Locator on a different port using Gfsh with...
gfsh> start locator --name=GemFireLocator --port=11235 --log-level=config
However, if you then want to connect the "SpringBootGemFireServer" to the "existing" Locator (i.e. "GemFireLocator" started in Gfsh), then you must change the spring.gemfire.locators application property to match (e.g. localhost[11235]). This in turn is captured here and set here.
Alternatively, you could have changed the value for spring.gemfire.start-locator application property to, say... localhost[12480], or just simply comment it out. This would have also avoided the j.n.BindException since the external Locator ("GemFireLocator") and the "embedded" Locator would then not conflict on port.
Technically, the spring.gemfire.start-locator should have been commented out by default in my sample. My apologies.
Other interesting tidbits about "SpringBootGemFireServer"... you have a CacheSever available for cache clients (i.e. ClientCache) applications to connect, hence...
Cache Server Information
Server Bind : localhost
Server Port : 40404
Running : true
Client Connections : 0
This comes from here.
And of course, you see the "Factorials" Region...
Regions : Factorials
So, regarding (which is probably apparent by now)...
Unbelievable, it succeed.
It seems like that your example is to start a new Gemfire locator and a server, not connect to a exist locator.
The SpringBootGemFireServer succeeded to start because you 1) stopped your "GemFireLocator" and 2) the SpringBootGemFireServer was running an "embedded" Locator, apparent from this.
If the SpringBootGemFireServer was not running the "embedded" Locator (service), then you would not have been able to connect (after you stopped your "GemFireLocator"), but you did...
gfsh>stop locator --name GemFireLocator
Stopping Locator running in C:\Users\IBM_ADMIN\GemFireLocator on ADMINIB-CI3Q48M[10334] as GemFireLocator...
Process ID: 7256
Log File: C:\Users\IBM_ADMIN\GemFireLocator\GemFireLocator.log
....
No longer connected to ADMINIB-CI3Q48M[1099].
gfsh>gfsh>list members
"list members" is not available. Reason: Requires connection.
gfsh>connect
Connecting to Locator at [host=localhost, port=10334] ..
Connecting to Manager at [host=ADMINIB-CI3Q48M, port=1199] ..
Successfully connected to: [host=ADMINIB-CI3Q48M, port=1199]
The "SpringBootGemFireServer" is also a "Manager", which is actually the reason you can connect in Gfsh.
When you use Gfsh's connect without an options, by default, connect tries to find a Locator on "localhost" listening on port 10334, hence this...
Connecting to Locator at [host=localhost, port=10334]
However, the Locator's responsibility is to find an existing Manager in the cluster and tell the client (i.e. Gfsh) where to find it (i.e. IP address/port). That is why you see the subsequent connect...
Connecting to Manager at [host=ADMINIB-CI3Q48M, port=1199] ..
All of that was made possible by this. If there is not already an existing "Manager" in the cluster, then the Locator is programmed/configured to become the "Manager". The jmx-manager GemFire property enables any member in the cluster to "become" a Manager. However, that does not mean it will startup as a Manager by default. To force the member to be a Manager at start, you must also set the jmx-manager-start GemFire property, as I have done with the SpringBootGemFireServer (of course, I default the value to false by default so it won't start as a Manager on startup). Anyway...
If you want to connect to an external, "existing" Locator (e.g. "GemFireLocator") started with Gfsh, then...
Run...
gfsh> start locator --name=GemFireLocator --log-level=config.
NOTE: keep in mind that GemFireLocator will be listening on the default port (10334) unless you specify the --port option to the start locator command.
Make sure you comment out line 8 in the application.properties file picked up by the "SpringBootGemFireServer" application. Alternatively, you can change the embedded Locators port by setting the spring.gemfire.start-locator application property to, say... localhost[11235].
(optional) If you set a port for your "external" / "existing" Locator (i.e. "GemFireLocator" started from Gfsh), then be sure to set the spring.gemfire.locators application property to match.
Hope this helps!
Regards,
-John

Related

Using UCANACCESS with Spring Boot

I am setting up a very basic Spring-Boot application, to serve some Access database content as a REST service.
After doing battle with getting the ucanaccess jar included in my classpath, now I'm having trouble getting it to connect to my access db.
My spring.datasource is set like this:
spring.datasource.jdbc-url=jdbc:ucanaccess://C:\\Users\\Owner\\Documents\\brigette.accdb;showSchema=true;memory=false
spring.datasource.dialect=net.ucanaccess.hibernate.dialect.UCanAccessDialect
The error I am getting is:
2020-04-08 09:01:28.534 INFO 20740 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-04-08 09:01:28.557 WARN 20740 --- [ main] o.h.e.j.e.i.JdbcEnvironmentInitiator : HHH000342: Could not obtain connection to query metadata : Failed to get driver instance for jdbcUrl=jdbc:ucanaccess://C:\Users\Owner\Documents\brigette.accdb;showSchema=true;memory=false
2020-04-08 09:01:28.563 WARN 20740 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [agency/newmeta/jsis/BackendDbConfig.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
2020-04-08 09:01:28.568 INFO 20740 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
The access database does exist in that location, but I do get the same error if I use a non-existant db.
HHH000342: Could not obtain connection to query metadata : Failed to get driver instance for jdbcUrl=jdbc:ucanaccess://C:\Users\Owner\Documents\lalala.accdb;showSchema=true;memory=false
and also if I use / instead of delimited :
HHH000342: Could not obtain connection to query metadata : Failed to get driver instance for jdbcUrl=jdbc:ucanaccess://C:/Users/Owner/Documents/brigette.accdb;showSchema=true;memory=false
What I am missing about setting up the conneciton string?
TIA
Brigette
I suggest you to use another approach: use spring jpa with hibernate.
And follow the article:
Accessing MS Access with Hibernate 5 and Spring Boot
At the end of the day it will guide you to implement a little app to read and update an accdb database.
The important thing to point out is the "patch" included in the source code that must be used in your code (without it , your app will never work).
The "patch" is the hibernate dialect: it is very important, it is reported in the source code of the article and shared at the end of the article.

NiFi fails to launch due to java.lang.IllegalArgumentException

I have been trying to launch NiFi, but everytime I do so I get the following error:
2019-03-06 18:53:46,935 ERROR [main] org.apache.nifi.NiFi Failure to
launch NiFi due to java.lang.IllegalArgumentException:
java.security.NoSuchAlgorithmException: md5 MessageDigest not
available java.lang.IllegalArgumentException:
java.security.NoSuchAlgorithmException: md5 MessageDigest not
available
at org.apache.nifi.nar.NarUnpacker.calculateMd5sum(NarUnpacker.java:419)
at org.apache.nifi.nar.NarUnpacker.unpackNar(NarUnpacker.java:228)
at org.apache.nifi.nar.NarUnpacker.unpackNars(NarUnpacker.java:123)
at org.apache.nifi.NiFi.(NiFi.java:128)
at org.apache.nifi.NiFi.(NiFi.java:71)
at org.apache.nifi.NiFi.main(NiFi.java:296) Caused by: java.security.NoSuchAlgorithmException: md5 MessageDigest not
available
at sun.security.jca.GetInstance.getInstance(GetInstance.java:159)
at java.security.Security.getImpl(Security.java:695)
at java.security.MessageDigest.getInstance(MessageDigest.java:167)
at org.apache.nifi.nar.NarUnpacker.calculateMd5sum(NarUnpacker.java:407)
... 5 common frames omitted 2019-03-06 18:53:46,939 INFO [Thread-1] org.apache.nifi.NiFi Initiating shutdown of Jetty web
server... 2019-03-06 18:53:46,940 INFO [Thread-1] org.apache.nifi.NiFi
Jetty web server shutdown completed (nicely or otherwise).
I understand this is coming from "calculateMd5sum " function that calculates md5 sum of a specified file. However, I have made no changes to any of Nars neither have I added any custom nars. The same instance did launch before.
I have also tried to start afresh by extracting the setup again, however I face the same error. I fail to understand why the issue is coming up all of a sudden. Please help!
I got it.
My java home pointed to "C:\Program Files\Java\jdk1.8.0_65"
changed the path to "C:\Program Files (x86)\Java\jre1.8.0_121"
It works fine now.
Thanks #BryanBende

org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'eurekaAutoServiceRegistration': Singleton bean crea

I'm developing a Spring Boot + Microservices example. I've taken reference from link: https://github.com/PacktPublishing/Mastering-Spring-Cloud/tree/master/Chapter06/sample-spring-cloud-comm-feign.
In this example, I'm able to start the discovery-service and gateway-service successfully, but when I tried to start any other service I am getting below error.
One thing which I notice that instructions are not very clear on how to execute the code even not mentioned clearly in the book.
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
19:05:25.564 ERROR
***************************
APPLICATION FAILED TO START
***************************
Description:
The Tomcat connector configured to listen on port 8080 failed to start. The port may already be in use or the connector may be misconfigured.
Action:
Verify the connector's configuration, identify and stop any process that's listening on port 8080, or configure this application to listen on another port.
19:05:25.564 INFO Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#1992eaf4: startup date [Mon Dec 24 19:05:14 IST 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext#48aca48b
19:05:25.564 INFO Unregistering application customer-service with eureka with status DOWN
19:05:25.564 WARN Saw local status change event StatusChangeEvent [timestamp=1545658525564, current=DOWN, previous=UP]
19:05:25.564 INFO DiscoveryClient_CUSTOMER-SERVICE/localhost:customer-service: registering service...
19:05:25.564 INFO Stopping beans in phase 0
19:05:25.579 INFO DiscoveryClient_CUSTOMER-SERVICE/localhost:customer-service - registration status: 204
19:05:26.017 INFO Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#4a064404: startup date [Mon Dec 24 19:05:26 IST 2018]; parent: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#1992eaf4
19:05:26.061 INFO JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
19:05:26.221 INFO Flipping property: localhost.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
19:05:26.221 INFO Shutdown hook installed for: NFLoadBalancer-PingTimer-localhost
19:05:26.254 INFO Client: localhost instantiated a LoadBalancer: DynamicServerListLoadBalancer:{NFLoadBalancer:name=localhost,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:null
19:05:26.288 INFO Using serverListUpdater PollingServerListUpdater
19:05:26.288 INFO DynamicServerListLoadBalancer for client localhost initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=localhost,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList#1ba156fc
19:05:26.585 INFO Unregistering JMX-exposed beans on shutdown
19:05:26.585 INFO Unregistering JMX-exposed beans
19:05:26.585 INFO Shutting down DiscoveryClient ...
19:05:26.585 INFO Unregistering ...
19:05:26.606 INFO DiscoveryClient_CUSTOMER-SERVICE/localhost:customer-service - deregister status: 200
19:05:26.607 INFO Completed shut down of DiscoveryClient
19:05:26.607 INFO Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#4a064404: startup date [Mon Dec 24 19:05:26 IST 2018]; parent: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#1992eaf4
19:05:26.607 WARN Exception thrown from ApplicationListener handling ContextClosedEvent
org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'eurekaAutoServiceRegistration': Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:216)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1078)
at org.springframework.context.event.ApplicationListenerMethodAdapter.getTargetBean(ApplicationListenerMethodAdapter.java:283)
at org.springframework.context.event.ApplicationListenerMethodAdapter.doInvoke(ApplicationListenerMethodAdapter.java:253)
at org.springframework.context.event.ApplicationListenerMethodAdapter.processEvent(ApplicationListenerMethodAdapter.java:177)
at org.springframework.context.event.ApplicationListenerMethodAdapter.onApplicationEvent(ApplicationListenerMethodAdapter.java:140)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:393)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:399)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:347)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:991)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:958)
at org.springframework.cloud.context.named.NamedContextFactory.destroy(NamedContextFactory.java:76)
at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:272)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:578)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:554)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:961)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:523)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.destroySingletons(FactoryBeanRegistrySupport.java:230)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:968)
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1030)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1006)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:958)
at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:750)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:134)
at pl.piomin.services.customer.CustomerApplication.main(CustomerApplication.java:22)
19:05:26.607 INFO Shutdown hook removed for: NFLoadBalancer-PingTimer-localhost
19:05:26.607 INFO Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#1491344a: startup date [Mon Dec 24 19:05:17 IST 2018]; parent: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#1992eaf4
19:05:26.607 WARN Exception thrown from ApplicationListener handling ContextClosedEvent
org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'eurekaAutoServiceRegistration': Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)
Change the port in application.yml where ever you have below properties. In your system the tomcat is probably running in default 8080 port.
server:
port: ${PORT:8080}
Hope the above change may help you.
https://github.com/spring-cloud/spring-cloud-netflix/commit/12583fd0c25638f95c14973d921ca28cdcd17df5
update your spring cloud version to Greenwich.SR6, the question will dispear

TomEE DataSource Resource gets "NoWait: Pool empty. Unable to fetch a connection, none available[5 in use]."

I'm running TomEE 7.0.1 in Eclipse Neon. I've defined a DataSource resource in the "tomee.xml" file. The DataSource connects to an Oracle DB, and I'm getting the driver from my local Maven repo.
When TomEE starts up, I get the following error in the console:
org.apache.tomcat.jdbc.pool.PoolExhaustedException: [main] NoWait: Pool empty. Unable to fetch a connection, none available[5 in use].
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:679)
at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:468)
at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:143)
at org.apache.tomee.jdbc.TomEEDataSourceCreator$TomEEConnectionPool.<init>(TomEEDataSourceCreator.java:221)
Here is my Resource definition:
<Resource id="global/foo/bar" type="DataSource" classpath="mvn:oracle:ojdbc6:11.2.0.3">
JdbcDriver = oracle.jdbc.driver.OracleDriver
MaxActive = 5
MinIdle = 2
MaxIdle = 2
MaxWait = 10000
JdbcUrl = jdbc:oracle:thin:#<host>:1521:sus2
UserName = <userid>
Password = <password>
</Resource>
I've elided the host, user, and password, but the id is as written. I'm still unsure about the JNDI lookup, but that's obviously a separate problem.
Here's my JNDI lookup reference in my Spring context:
<jee:jndi-lookup jndi-name="java:global/foo/bar" id="sus2ds"/>
And here is more of the Tomcat console output:
INFO: Configuring Service(id=global/foo/bar, type=Resource, provider-id=Default JDBC Database)
...
INFO: Creating Resource(id=global/foo/bar)
Aug 03, 2016 11:08:27 AM org.apache.tomcat.jdbc.pool.ConnectionPool checkPoolConfiguration
WARNING: initialSize is larger than maxActive, setting initialSize to: 5
Aug 03, 2016 11:08:27 AM org.apache.tomcat.jdbc.pool.ConnectionPool init
SEVERE: Unable to create initial connections of pool.
org.apache.tomcat.jdbc.pool.PoolExhaustedException: [main] NoWait: Pool empty. Unable to fetch a connection, none available[5 in use].
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:679)
at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:468)
at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:143)
at org.apache.tomee.jdbc.TomEEDataSourceCreator$TomEEConnectionPool.<init>(TomEEDataSourceCreator.java:221)
...
Aug 03, 2016 11:08:27 AM org.apache.tomee.jdbc.TomEEDataSourceCreator$TomEEDataSource <init>
SEVERE: Can't create DataSource
org.apache.tomcat.jdbc.pool.PoolExhaustedException: [main] NoWait: Pool empty. Unable to fetch a connection, none available[5 in use].
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:679)
at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:468)
at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:143)
at org.apache.tomee.jdbc.TomEEDataSourceCreator$TomEEConnectionPool.<init>(TomEEDataSourceCreator.java:221)
...
...
2016-08-03 11:08:30,080 WARN [localhost-startStop-1] support.AbstractApplicationContext (AbstractApplicationContext.java:549) - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sus2ds': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name "foo/bar" not found.
2016-08-03 11:08:30,084 ERROR [localhost-startStop-1] context.ContextLoader (ContextLoader.java:351) - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sus2ds': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name "foo/bar" not found.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
...
Caused by: javax.naming.NameNotFoundException: Name "foo/bar" not found.
at org.apache.openejb.core.ivm.naming.IvmContext.federate(IvmContext.java:199)
at org.apache.openejb.core.ivm.naming.IvmContext.lookup(IvmContext.java:151)
at org.apache.openejb.core.ivm.naming.IvmContext.lookup(IvmContext.java:291)
at org.apache.naming.NamingContext.lookup(NamingContext.java:828)
...
Aug 03, 2016 11:08:30 AM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sus2ds': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name "foo/bar" not found.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
...
Caused by: javax.naming.NameNotFoundException: Name "foo/bar" not found.
at org.apache.openejb.core.ivm.naming.IvmContext.federate(IvmContext.java:199)
at org.apache.openejb.core.ivm.naming.IvmContext.lookup(IvmContext.java:151)
at org.apache.openejb.core.ivm.naming.IvmContext.lookup(IvmContext.java:291)
at org.apache.naming.NamingContext.lookup(NamingContext.java:828)
...
I would start the server and use an MBean explorer, or the JNDI explorer webapp, to take a look at the JNDI tree and get the correct name. My suspicion is you do not need id="global/foo/bar" but id="foo/bar" and keep the lookup the same in your Spring code.

Cloudfoundry Spring MongoDB sample application fails to deploy

When I try to deploy the sample Java Spring application with MongoDB (hello-spring-mongodb) I get the error pasted below, which suggests the MongoDB service is failing to bind. I have been getting this error in all my own applications too, deploying both from the command line and from STS 3.0.0. The key error is:
Error creating bean with name 'mongoDbFactory': Invocation of init method failed; nested exception is
org.cloudfoundry.runtime.env.CloudServiceException: Expected 1 service of class org.cloudfoundry.runtime.env.MongoServiceInfo type, but found0
Full trace:
Bind existing services to 'hello-weeels'? [yN]:
Create services to bind to 'hello-weeels'? [yN]: y
1: mongodb
2: mysql
3: postgresql
4: rabbitmq
5: redis
What kind of service?: 1
Specify the name of the service [mongodb-9c56b]:
Create another? [yN]: n
Would you like to save this configuration? [yN]: y
Manifest written to manifest.yml.
Creating Application: OK
Creating Service [mongodb-9c56b]: OK
Binding Service [mongodb-9c56b]: OK
Uploading Application:
Checking for available resources: OK
Processing resources: OK
Packing application: OK
Uploading (3K): OK
Push Status: OK
Staging Application 'hello-weeels': OK
Starting Application 'hello-weeels': ..
Error: Application [hello-weeels] failed to start, logs information below.
====> /logs/stderr.log <====
Aug 27, 2012 9:17:24 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-54519
Aug 27, 2012 9:17:24 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 392 ms
Aug 27, 2012 9:17:24 PM org.apache.catalina.realm.JAASRealm setContainer
INFO: Set JAAS app name Catalina
Aug 27, 2012 9:17:24 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Aug 27, 2012 9:17:24 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.35
Aug 27, 2012 9:17:24 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory ROOT
Aug 27, 2012 9:17:24 PM org.cloudfoundry.reconfiguration.CloudAutoStagingBeanFactoryPostProcessor usingCloudService
INFO: Found an instance of org.cloudfoundry.runtime.service.AbstractCloudServiceFactory. Autostaging will be skipped.
Aug 27, 2012 9:17:25 PM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
Aug 27, 2012 9:17:25 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [] startup failed due to previous errors
====> /logs/stdout.log <====
INFO : org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization started
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Refreshing Root WebApplicationContext: startup date [Mon Aug 27 21:17:24 UTC 2012]; root of context hierarchy
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [root-context.xml]
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [META-INF/cloud/cloudfoundry-auto-reconfiguration-context.xml]
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#c292cb2: defining beans [mongoTemplate,mongoDbFactory,__appCloudJpaPostgreSQLReplacementProperties,__appCloudJpaMySQLReplacementProperties,__appCloudHibernatePostgreSQLReplacementProperties,__appCloudHibernateMySQLReplacementProperties,org.cloudfoundry.reconfiguration.CloudAutoStagingBeanFactoryPostProcessor#0]; root of factory hierarchy
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#c292cb2: defining beans [mongoTemplate,mongoDbFactory,__appCloudJpaPostgreSQLReplacementProperties,__appCloudJpaMySQLReplacementProperties,__appCloudHibernatePostgreSQLReplacementProperties,__appCloudHibernateMySQLReplacementProperties,org.cloudfoundry.reconfiguration.CloudAutoStagingBeanFactoryPostProcessor#0]; root of factory hierarchy
ERROR: org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoTemplate' defined in class path resource [root-context.xml]: Cannot resolve reference to bean 'mongoDbFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoDbFactory': Invocation of init method failed; nested exception is org.cloudfoundry.runtime.env.CloudServiceException: Expected 1 service of class org.cloudfoundry.runtime.env.MongoServiceInfo type, but found0
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:630)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:148)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1035)
Replace:
<beans profile="default">
<mongo:db-factory id="mongoDbFactory" dbname="pwdtest" host="127.0.0.1" port="27017" username="mongo_user" password="passwd"/>
</beans>
<beans profile="cloud">
<cloud:mongo-db-factory id="mongoDbFactory"/>
</beans>
With:
<mongo:db-factory
id="mongoDbFactory"
dbname="${mongo.name}"
host="${mongo.host}"
port="27017"
username="${mongo.username}"
password="${mongo.password}" />
...and cloudfoundry auto reconfig will do it's job properly. If you still have a problem, Right-click on your project in the Spring Explorer View > Properties, and enable the "Beans Validator".
Did you change the name of the expected mongo db? The hello-spring-mondgodb app is configured to to look for a db named 'hello' (The second constructor arg of SimpleMongoDbFactory). Maybe try updating this property to reflect the name of your mongo db and re-push.
Hope this helps
Chris
The hello-spring-mongodb runs without configuration changes. It deploys successfully on my CF installation. First, I create a mongoDB service with:
vmc create-service mongoDB
and then I run: vmc push hello-sping-mongodb from the target directory
C:\eclipseWork\Indigo\hello-spring-mongodb\target>vmc push hello-spring-mongodb
Would you like to deploy from the current directory? [Yn]:
Detected a Java SpringSource Spring Application, is this correct? [Yn]:
Application Deployed URL [hello-spring-mongodb.vcap.me]:
Memory reservation (128M, 256M, 512M, 1G, 2G) [512M]:
How many instances? [1]:
Bind existing services to 'hello-spring-mongodb'? [yN]: y
1: mongodb-86f0e
Which one?: 1
Create services to bind to 'hello-spring-mongodb'? [yN]:
Would you like to save this configuration? [yN]:
Creating Application: OK
Binding Service [mongodb-86f0e]: OK
Uploading Application:
Checking for available resources: OK
Processing resources: OK
Packing application: OK
Uploading (2K): OK
Push Status: OK
Staging Application 'hello-spring-mongodb': OK
Starting Application 'hello-spring-mongodb': OK
Can you try to create the mongoDB service first and then push the application?
It seems that the cloud profile configuration isn't defined in your root-context.xml. Check again that you have the following configuration:
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg ref="mongoDbFactory"/>
</bean>
<beans profile="default">
<mongo:db-factory id="mongoDbFactory" dbname="pwdtest" host="127.0.0.1" port="27017" username="mongo_user" password="passwd"/>
</beans>
<beans profile="cloud">
<cloud:mongo-db-factory id="mongoDbFactory"/>
</beans>
Make sure the service name matches, and update the cloudfoundry-runtime version. See my answer to another question with the same exception here.

Resources