I have a jar of a spring boot application running in a docker container. I am trying to connect it to a neo4j docker container. I get an error when I hit the url http://localhost:8080/ "Could not open Neo4j Session for transaction". But when I run the jar and neo4j container from two separate machines it connects to the neo4j db. Error only occurs if I run both containers on same host machine. Below is the log:
2019-02-25 09:02:52.413 ERROR 6 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open Neo4j Session for transaction; nested exception is org.neo4j.ogm.exception.ConnectionException: Could not create driver instance] with root cause
java.net.ConnectException: Connection refused
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) ~[na:1.8.0_111]
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717) ~[na:1.8.0_111]
at org.neo4j.driver.internal.shaded.io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:325) ~[neo4j-java-driver-1.6.3.jar!/:1.6.3-b33d284ef6f350edbfe9e8f4539cdcdb0200bd0b]
Don't bind your database to localhost.
Bind to any IP 0.0.0.0
Please read my answers here and here. It's help to people have the same problems
Related
A legacy Spring boot project, before it used mongo, but now it does not need. Now start this project it has this error
2022-10-27 14:10:13.119 [cluster-ClusterId{value='635a20bb714f8f71e2e5d041', description='null'}-10.48.51.21:40010] [INFO] [org.mongodb.driver.cluster] - Exception in monitor thread while connecting to server 10.48.51.21:40010
com.mongodb.MongoSocketOpenException: Exception opening socket
at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:70)
at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:127)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.net.SocketTimeoutException: connect timed out
at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
then I exclude related Auto Configuration class
#SpringBootApplication(exclude={MongoAutoConfiguration.class, MongoRepositoriesAutoConfiguration.class,MongoDataAutoConfiguration.class})
but this time project start failed
***************************
APPLICATION FAILED TO START
***************************
Description:
Field mongoTemplate in com.bxt.bmht_support.dao.BmhtMideTableDao required a bean of type 'org.springframework.data.mongodb.core.MongoTemplate' that could not be found.
How to disable mongo without update current code? just want ignore it.
I'm trying to run a server on my laptop and connect to it from my desktop
But every time I get the following error, but if I dig deeper I see
Caused by: java.net.ConnectException: Connection refused: connect"
The client does not run if the server is not running.
I tried running the client and the server both on the same computer and it works.
I tried pinging the computers from one another and it works.
I wonder what am I doing wrong?
I'm using Maven.
[INFO]
[INFO] --- exec-maven-plugin:3.0.0:java (client) # client ---
Exception in Application start method
[WARNING]
java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1 (LauncherImpl.java:900)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2 (LauncherImpl.java:195)
at java.lang.Thread.run (Thread.java:833)
Caused by: java.net.ConnectException: Connection refused: connect
at sun.nio.ch.Net.connect0 (Native Method)
at sun.nio.ch.Net.connect (Net.java:579)
at sun.nio.ch.Net.connect (Net.java:568)
at sun.nio.ch.NioSocketImpl.connect (NioSocketImpl.java:585)
at java.net.SocksSocketImpl.connect (SocksSocketImpl.java:327)
at java.net.Socket.connect (Socket.java:633)
at java.net.Socket.connect (Socket.java:583)
at java.net.Socket.<init> (Socket.java:507)
at java.net.Socket.<init> (Socket.java:287)
at il.cshaifasweng.OCSFMediatorExample.client.ocsf.AbstractClient.openConnection (AbstractClient.java:136)
at il.cshaifasweng.OCSFMediatorExample.client.App.start (App.java:29)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9 (LauncherImpl.java:846)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12 (PlatformImpl.java:455)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$10 (PlatformImpl.java:428)
at java.security.AccessController.doPrivileged (AccessController.java:399)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$11 (PlatformImpl.java:427)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run (InvokeLaterDispatcher.java:96)
at com.sun.glass.ui.win.WinApplication._runLoop (Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3 (WinApplication.java:174)
at java.lang.Thread.run (Thread.java:833)
I solved this by using clientSocket= new Socket("MY IP", "MY PORT");
"MY IP" will be inserted as string
"MY PORT" will be inserted as an int\
instead of clientSocket= new Socket(host, port);
I have written an RestAPI server that uses mongodb with spring, and successfully tested it locally. But, when I am deploying the war file on my server (tomcat) it causes an error.
After searching, I added "compile 'org.mongodb:mongo-java-driver:2.13.3'" to my build.gradle/pom.xml file based on a tutorial. But, I don't know what to do next to solve the error. I assume it has something to do with initializing a mongodb. Here is my error on Jenkins when it tries do deploys it:
BUILD SUCCESSFUL in 6s
4 actionable tasks: 4 executed
Build step 'Invoke Gradle script' changed build result to SUCCESS
Deploying /var/jenkins_home/workspace/AddressBook/build/libs/AddressBook.war to container Tomcat 8.x Remote with context
Redeploying [/var/jenkins_home/workspace/AddressBook/build/libs/AddressBook.war]
Undeploying [/var/jenkins_home/workspace/AddressBook/build/libs/AddressBook.war]
Deploying [/var/jenkins_home/workspace/AddressBook/build/libs/AddressBook.war]
ERROR: Build step failed with exception
org.codehaus.cargo.container.ContainerException: Failed to deploy [/var/jenkins_home/workspace//AddressBook/build/libs/AddressBook.war]
at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.deploy(AbstractTomcatManagerDeployer.java:106)
at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:184)
at hudson.plugins.deploy.CargoContainerAdapter.deploy(CargoContainerAdapter.java:77)
at hudson.plugins.deploy.CargoContainerAdapter$DeployCallable.invoke(CargoContainerAdapter.java:147)
at hudson.plugins.deploy.CargoContainerAdapter$DeployCallable.invoke(CargoContainerAdapter.java:117)
at hudson.FilePath.act(FilePath.java:997)
at hudson.FilePath.act(FilePath.java:975)
at hudson.plugins.deploy.CargoContainerAdapter.redeploy(CargoContainerAdapter.java:114)
at hudson.plugins.deploy.PasswordProtectedAdapterCargo.redeploy(PasswordProtectedAdapterCargo.java:93)
at hudson.plugins.deploy.DeployPublisher.perform(DeployPublisher.java:64)
at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:45)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:744)
at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:690)
at hudson.model.Build$BuildExecution.post2(Build.java:186)
at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:635)
at hudson.model.Run.execute(Run.java:1749)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:429)
Caused by: org.codehaus.cargo.container.tomcat.internal.TomcatManagerException: The Tomcat Manager responded "FAIL - Deployed application at context path [/AddressBook] but context failed to start
" instead of the expected "OK" message
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.invoke(TomcatManager.java:715)
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.deployImpl(TomcatManager.java:761)
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.deploy(TomcatManager.java:312)
at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.deploy(AbstractTomcatManagerDeployer.java:101)
... 18 more
org.codehaus.cargo.container.tomcat.internal.TomcatManagerException: The Tomcat Manager responded "FAIL - Deployed application at context path [/AddressBook] but context failed to start
" instead of the expected "OK" message
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.invoke(TomcatManager.java:715)
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.deployImpl(TomcatManager.java:761)
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.deploy(TomcatManager.java:312)
at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.deploy(AbstractTomcatManagerDeployer.java:101)
at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:184)
at hudson.plugins.deploy.CargoContainerAdapter.deploy(CargoContainerAdapter.java:77)
at hudson.plugins.deploy.CargoContainerAdapter$DeployCallable.invoke(CargoContainerAdapter.java:147)
at hudson.plugins.deploy.CargoContainerAdapter$DeployCallable.invoke(CargoContainerAdapter.java:117)
at hudson.FilePath.act(FilePath.java:997)
at hudson.FilePath.act(FilePath.java:975)
at hudson.plugins.deploy.CargoContainerAdapter.redeploy(CargoContainerAdapter.java:114)
at hudson.plugins.deploy.PasswordProtectedAdapterCargo.redeploy(PasswordProtectedAdapterCargo.java:93)
at hudson.plugins.deploy.DeployPublisher.perform(DeployPublisher.java:64)
at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:45)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:744)
at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:690)
at hudson.model.Build$BuildExecution.post2(Build.java:186)
at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:635)
at hudson.model.Run.execute(Run.java:1749)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:429)
Build step 'Deploy war/ear to a container' marked build as failure
Finished: FAILURE
My application is something like https://spring.io/guides/gs/accessing-data-mongodb/, with some RestAPI mappings.
And here is the tomcat log:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'per
sonController': Unsatisfied dependency expressed through field 'PersonRepo'; nested exception is org
.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personRepositor
y': Cannot resolve reference to bean 'mongoTemplate' while setting bean property 'mongoOperations';
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating
bean with name 'mongoTemplate' defined in class path resource [org/springframework/boot/autoconfigu
re/data/mongo/MongoDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'mo
ngoTemplate' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependenc
yException: Error creating bean with name 'mongoDbFactory' defined in class path resource [org/sprin
gframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.class]: Unsatisfied dependency e
xpressed through method 'mongoDbFactory' parameter 0; nested exception is org.springframework.beans.
factory.BeanCreationException: Error creating bean with name 'mongo' defined in class path resource
[org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.class]: Bean instantiation via
factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Fai
led to instantiate [com.mongodb.MongoClient]: Factory method 'mongo' threw exception; nested excepti
on is java.lang.IllegalAccessError: tried to access method org.bson.types.ObjectId.<init>(III)V from
class com.mongodb.Bytes
UPDATE (fix of above error):
So, I had this as dependency in my build.gradle:
compile 'org.mongodb:mongo-java-driver:2.13.3'
I changed it to (not enforcing version):
compile group: 'org.mongodb', name: 'mongo-java-driver'
But, now when I request a GET from my server, I see:
Sun Mar 04 21:05:23 UTC 2018
There was an unexpected error (type=Internal Server Error, status=500).
Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused (Connection refused)}}]; nested exception is com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused (Connection refused)}}]
Here is my application.properties:
spring.data.mongodb.host=<server_address>
spring.data.mongodb.port=27017
spring.data.mongodb.user=<username>
MongoDB server on localhost:27017 (user , pwd: same as /var/jenkins_home).
Should I somehow tell my application about the path of mongoDB?
Or should I tell my application about the database name? (I think it will use some default one)
I have installed rabbit MQ in docker, my host machine OS is windows. Now I am not able to access rabbit mq instance present in my docker but others can access the same using my Ip address. While trying to connect using spring boot amqp I am getting error
org.springframework.amqp.AmqpIOException: java.io.IOException .....
Caused by: java.io.IOException: null .....
Caused by: com.rabbitmq.client.ShutdownSignalException: connection error....
Caused by: java.net.SocketException: Connection reset.....
I have a Jetty 6 server running a grails 1.1 (which in turn uses hibernate) application. Since sometimes it goes down, I'd like it to automatically restart if something happens. So, I heard about Monit and decided to give it a try. I've created the following configuration:
check process jetty with pidfile /var/run/jetty.pid
group nfetron
start program = "/data/ebs/NFeTron/bin/jetty.sh start"
stop program = "/data/ebs/NFeTron/bin/jetty.sh stop"
if failed host "localhost" port 8090 protocol HTTP with timeout 10 seconds then restart
if mem usage > 95% for 11 cycles then restart
Well, the problem is that when the Monit starts the Jetty, it doesn't run normally. It fails to connect to the database, as seen in the following log:
2017-02-13 21:35:34.356::INFO: jetty-6.1.14
2017-02-13 21:35:34.404::INFO: Deploy /data/ebs/NFeTron/contexts/javadoc.xml -> org.mortbay.jetty.handler.ContextHandler#153f5a29{/javadoc,file:/data/ebs/NFeTron/java$
2017-02-13 21:35:34.536::INFO: No Transaction manager found - if your webapp requires one, please configure one.
2017-02-13 21:35:34.875::INFO: No Transaction manager found - if your webapp requires one, please configure one.
2017-02-13 21:35:35.404::INFO: No Transaction manager found - if your webapp requires one, please configure one.
2017-02-13 21:35:37.337:/NFeTron:INFO: Initializing Spring root WebApplicationContext
loading security config ...
2017-02-13 21:35:54.383::WARN: Failed startup of context org.mortbay.jetty.webapp.WebAppContext#770c2e6b{/NFeTron,file:/data/ebs/NFeTron/webapps/NFeTron/}
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springfr$
at java.security.AccessController.doPrivileged(Native Method)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactor$
at java.security.AccessController.doPrivileged(Native Method)
... 1 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception $
at java.security.AccessController.doPrivileged(Native Method)
... 2 more
Caused by: java.lang.NullPointerException
... 3 more
2017-02-13 21:35:54.384::WARN: Nested in org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initialization of bea$
java.lang.NullPointerException
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessController.doPrivileged(Native Method)
2017-02-13 21:35:54.390::INFO: Opened /data/ebs/NFeTron/logs/2017_02_13.request.log
2017-02-13 21:35:54.456::INFO: Started SelectChannelConnector#0.0.0.0:8090
I searched a lot and couldn't find anyone facing the same problem. When I start the application using SSH (with root user), it works normally. But when Monit starts it (supposedly with root user), it doesn't. Does anyone have any clue about this problem?