Neo4J connection timed out in Spring Boot 2.2.4 but not in 2.0.5 - spring-boot

I'm building a Spring Boot application with neo4j. I have an issue connecting to a deployed database when I'm running on Spring Boot 2.2.4. In an other project with Spring Boot 2.0.5 it works, but when I upgrade that project to 2.2.4 it also breaks with the same exception.
The weird thing is that it also works on 2.2.4 locally when using a local Docker image.
I get the following exception when I try to connect to a deployed neo4j instance in the cloud using an uri of the form bolt://35.xx.xx.xx:7687 AND on Spring Boot 2.2.4:
If I run my docker image and I change the connection uri to bolt://localhost:7687 it also works perfectly fine on Spring Boot 2.2.4.
Even in my gitlab CI/CD pipeline the test works fine using a service inside the pipeline, also with the same neo4j image.
This is my build.gradle:
And these are the versions effectively installed:
I also can always use browser to connect to my database that's why I assume that it has something to do with the versions instead of my cloud configuration.
Anyone any idea what I have to change on my configuration?
Thanks in advance!
We run following versions:
neo4j 3.5.14
Spring Boot 2.2.4
Java 11
EDIT 1
As someone proposed, I also setup a very simplistic example application (https://neo4j.com/developer/java/) using just the neo4j driver v4 with my GCP instance of Neo4J. This works perfectly fine.
EDIT 2
My application.properties looks like this:
spring.data.neo4j.uri=bolt://35.xxx.xxx.xxx:7687 # <- in prod
spring.data.neo4j.uri=bolt://localhost:7687 # <- in dev
spring.data.neo4j.uri=bolt://neo4j:7687 # <- in CI/CD
spring.data.neo4j.username=neo4j
spring.data.neo4j.password=****
spring.data.neo4j.embedded.enabled=false
The different environments are splitted in seperate property files that set the spring active profile. Im always testing this with replacing the localhost one in the application-dev.properties to the public ip.

My final setup (and solution) was to use only following dependencies:
implementation 'org.springframework.boot:spring-boot-starter-data-neo4j'
implementation 'org.neo4j.driver:neo4j-java-driver-spring-boot-starter:4.0.0.1'
And use following settings in the properties file:
org.neo4j.driver.uri=bolt://35.xx.xx.xx:7687
org.neo4j.driver.authentication.username=neo4j
org.neo4j.driver.authentication.password=neo4j
org.neo4j.driver.config.encrypted=false
Encryption wasn't the problem, but the settings had to be set to org.neo4j.driver instead of the org.springramework.boot dependency. The springframework dependency is still needed to use #Query etc in the repositories, thats why I needed both.

Related

HttpServletRequest getLocalAddr not returning local address after migrating to spring 2.1.6

I've recently upgrading spring boot from 2.1.0 to 2.1.6 and now HttpServletRequest.getLocalAddr() does not behave as expected anymore.
For context, I have a web client and a spring server. When the client connects to the server, the latter sends its IP address to the former.
In 2.1.0 and up to 2.1.5 it worked as expected: getLocalAddr returns the local address of the spring server. However, in 2.1.6 it now returns the local address of the client.
Spring-boot 2.1.5 use tomcat 9.0.19
Spring-boot 2.1.6 should use tomcat 9.0.20 according to the release not but when I execute mvn dependency:tree I find that it uses 9.0.21.
I'd like to know if I'm using getLocalAddr properly or not and eventually if I should raise the issue to spring-boot or tomcat.
I've confirmed that the issue occurs in spring 2.1.6 with tomcat 9.0.21.
The issue does not occur in spring 2.1.5 with tomcat 9.0.19
I'm not able to provide a minimal working example, but here is a bit of code demonstrating my usage.
#RestController
public class DeviceControllerImpl {
//omitting
#GetMapping("/configuration")
public String sendConfig(HttpServletRequest http_request) {
String ip = http_request.getLocalAddr();
}
}
I'm expecting getLocalAddr to return the local IP address of spring server, not the web client.
This was a regression bug in tomcat 9.0.21 which is the version provided by spring boot 2.1.6. There is a fix in 9.0.23. Details here: https://bz.apache.org/bugzilla/show_bug.cgi?id=63570
It was a regression in Tomcat version 9.0.22, but was fixed in version 9.0.23. Note however that version 9.0.23 is not on mvnrepository.com, so I would go for version 9.0.24.
To fix it for Spring Boot (and assuming the spring-boot-starter-parent is specified as your project's parent) just specify the new version of Tomcat in your POM's properties:
<tomcat.version>9.0.24</tomcat.version>
See:
https://bz.apache.org/bugzilla/show_bug.cgi?id=63570
https://mvnrepository.com/artifact/org.apache.tomcat.embed/tomcat-embed-core

Two or more spring boot application sharing same port

I have a use case where I need to run atleast two or more spring boot applications on the same port.
I am able to run spring boot applications via mvn spring-boot:run -Pdev... port and other information. I have provided following configuration in spring boot projects
server.port= 8597
server.contextPath=<as per the project>
spring.config.name=<project name>
With this configuration, I successfully run two spring boot application on same port i.e. 8587.
Now, here the problem comes, when I package the project as jar for dist purposes and run the application as java -jar <profile>..... second boot project run fails with Address already in use.
I am not able to understand where I am going wrong. I even tried passing context, port and config name in vm arguments but no success.
Any help?

How to connect SpringBoot (on Wildfly) to MySQL on openshift 3?

To put a SpringBoot application on openshift 3 the suggested route is by using the s2i of Wildfly. For the moment this is sufficient for me.
How can I conect SpringBoot (on Wildfly) to MySQL at openshift 3?
Please show how I can use environment variables and/ linking.
Do I need to prepare the maven file to produce SpringBoot as a war?
The free eBook at:
https://www.openshift.com/promotions/for-developers.html
Uses a Wildfly application and connects it to a database. See if that will work for your situation.

How do you write a Spring Cloud Config Server with Spring Boot (1.5.3.RELEASE) and Spring Cloud Config (1.3.0.RELEASE)?

I modified the spring-cloud-config-server-mongodb project to use the latest version of Spring Boot (1.5.3.RELEASE) and Spring Cloud Config (1.3.0.RELEASE).
I also introduced the class MongoConfigServer that runs the mongo db config server.
When I run it, I get this error:
org.springframework.beans.factory.NoUniqueBeanDefinitionException:
No qualifying bean of type
'org.springframework.cloud.config.server.environment.EnvironmentRepository' available:
more than one 'primary' bean found among candidates: [searchPathLocator, environmentRepository, searchPathCompositeEnvironmentRepository]
I am not sure what I did wrong. How do I write my own config server without getting this error?
I don't see any documentation on how to do this.
Can somebody please help me, or guide me?
This mongo db config server used to work with older versions of Spring Boot and Spring Cloud Config.
I am using this Mongo DB Config Server as an example for writing a different Config Server, which is also receiving the same error.
My fork of spring-cloud-config-server-mongodb is available at https://github.com/minmay/spring-cloud-config-server-mongodb.git
The spring-cloud-config-server-mongodb project has been upgraded to use spring-boot 1.5.7 snapshots.
I fixed this issue by updating https://github.com/minmay/spring-cloud-config-server-mongodb/blob/master/src/main/java/org/springframework/cloud/config/server/mongodb/config/MongoEnvironmentRepositoryConfiguration.java.
What I did was I removed the searchPathLocator bean, and removed the primary annotation from environmentRepository.
I guess Spring Cloud Config was updated to conditionally find an environmentRepository bean.

how to deploy Spring boot actuate application in external tomcat server

Im trying to just use the basic endpoints that comes with spring actuate and want to deploy in the external tomcat server without using spring boot. How to achieve this, could anyone help me please. Is there any configuration changes that I need to do. This website gives an idea but it uses older version of spring-boot-actuate. Also EndpointHandlerMapping and EndpointHandlerAdapter doesnt come with newer version of spring boot actuate.
Anyways I get 404 resource not found when deploying to the server.
Check out this question to see if it helps you. The Actuator component is a Spring Boot feature but you can use individual components within an existing application with the right build and configuration setups.

Resources