Spring R2DBC doesn't support multiple host/failover - spring

I'm using spring r2dbc in my project and trying to make it work with multiple host/failover postgres topology; in other words, where the db url is like this: r2dbc:postgresql:failover://host1,host2,host3:port/
I'm using 2.7.5 version of spring boot, and get:
r2dbc-pool-0.9.2.RELEASE
r2dbc-spi-0.9.1.RELEASE
r2dbc-postgresql-0.9.2.RELEASE
as a part of spring boot.
As far as I understand, this set of r2dbc libs doesn't support failover yet, since I see errors stating that such url can not be parsed.
I tried to upgrade r2dbc-postgresql-0.9.2.RELEASE to 1.0.0.RC1 but I'm getting the following error:
class java.lang.Long cannot be cast to class java.lang.Integer
(java.lang.Long and java.lang.Integer are in module java.base of loader 'bootstrap')
java.lang.ClassCastException: class java.lang.Long cannot be cast to class java.lang.Integer
(java.lang.Long and java.lang.Integer are in module java.base of loader 'bootstrap')
as a result of executing simple delete query DELETE FROM my_table WHERE boolean_flag = $1
Which indirectly says that there is some compatibility issue in r2dbc libs. Can anyone guide me if there is working set of these libs that can work in my case or is waiting for new spring release is my only option?

As of Spring boot version 2.7.5 (and as far as I know any version lower then 3.0.0) there is no valid option to use postgres/spring boot/r2dbc/multiple host failover composition in your project. It is just not supported for now.
But the good news is that it should be supported in the Spring boot 3.0.0 version which is going to be released very soon.
Quote from Mark Paluch, the active member of r2dbc gitter:
R2DBC 1.0 is supported by Spring Framework 6/Spring Data R2DBC 3.0 as there's a binary compatibility change between R2DBC 0.9 and 1.0

Related

RestHighLevelClient Bean for elasticsearch not found on classpath in spring boot 3

I am trying to upgrade my existing spring boot 2.7.x project to spring boot 3.x.x.
I have sorted out everything except this error while running the application.
APPLICATION FAILED TO START
Description:
Parameter 0 of method lockProvider in com.cox.config.ShedLockConfiguration required a bean of type 'org.elasticsearch.client.RestHighLevelClient' that could not be found.
Action:
Consider defining a bean of type 'org.elasticsearch.client.RestHighLevelClient' in your configuration.
Process finished with exit code 0
Spring Boot Version used is 3.0.0
I am aware that RestHighLevelClient is deprecated, but documentation says it's still available in spring-data-elasticsearch
Tried upgrading all dependencies to be compatible with spring boot 3
Update:
Also getting below error for another component with elastic search which I am trying to upgrade to spring boot 3
APPLICATION FAILED TO START
Description:
Parameter 2 of constructor in com.cox.service.esindex.EsIndexRefreshService required a bean of type 'org.springframework.data.elasticsearch.core.ElasticsearchOperations' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.data.elasticsearch.core.ElasticsearchOperations' in your configuration.
It looks like spring boot is no longer creating beans for deprecated methods/classes. Can you please help me map each deprecated method/class with the new spring-data-elasticsearch
The documentation explicitly states:
The old deprecated RestHighLevelClient can still be used, but you will need to add the dependency explicitly to your application as Spring Data Elasticsearch does not pull it in automatically anymore:
Edit 18.02.2023:
Check the documentation it also documents how to configure the different clients. You will have to do this configuraiton by yourself, I don't think that Spring Boot will configure this automatically, they are using the current stuff from Spring Data Elasticsearch .

Using Hibernate 6.x with Spring Boot 2.7.x not working?

I am trying to use Hibernate Core 6.x with Spring Boot / Spring Data JPA 2.7.x project, but it's not able to pick up Hibernate 6.x classes.
As you can see in the pom, in spring-boot-starter-data-jpa I have excluded hibernate-core 5.6.10-final and added 6.x as project dependency.
But I am seeing below error:
***************************
APPLICATION FAILED TO START
***************************
Description:
A component required a bean of type 'javax.persistence.EntityManagerFactory' that could not be found.
Action:
Consider defining a bean of type 'javax.persistence.EntityManagerFactory' in your configuration.
I don't think spring boot is autoconfiguring the new Hibernate 6.x version.
For 5.6.x, I could see below 11 implementations for EntityManager.
On moving to 6.x, I see only one implementation.
What's going on, I have no idea. Can some one pitch in and help resolve this issue.
Why I want 6.x -> See if RIGHT JOIN work in 6.x. Even other wise I see it's going to be a good task to figure out and make this combo work.
Hibernate 6 uses the JPA version (JPA 3) that uses the jakarta.persistence package names introduced in JakartaEE 9. Spring Boot 2.x still uses the javax.* package namespace of JakartaEE 8 and earlier (JPA 2.2 and earlier), and thus only supports Hibernate 5.x (for Spring Boot 2.7, Hibernate 5.6.x is the default).
Spring Boot 3 switched to the jakarta.* packages of JakartaEE 9+. So, you can upgrade to Spring Boot 3 to able to use Hibernate 6. If you cannot upgrade Spring Boot yet, you'll need to use Hibernate 5.6.

Spring-Kafka: RecordIntercepter class not found

I am using spring boot 2.1.5 and spring-kafka, version not specified. Project is gradle 6.0, java 1.8
I am getting this error
error creating bean with name 'org.springframework.boot.autoconfigure.kafka.kafkaannotationdrivenconfiguration': unexpected exception during bean creation; nested exception is java.lang.typenotpresentexception: type org.springframework.kafka.listener.recordinterceptor not present
What could be this due to? Please help.
2.1.5 is nearly a year old; the current Boot 2.1.x release is 2.1.13.
2.1.5 uses spring-kafka 2.2.6 so I don't see how you can get that error, based on your description.
RecordInterceptor was added in spring-kafka 2.2.7.
It was added to the Spring Boot autoconfiguration in 2.2.0.
So what you are describing makes no sense; you must be using Boot 2.2.x and an old spring-kafka version.
You have mis-matched Boot/Kafka versions.
Upgrade to Boot 2.1.13 (or preferably 2.2.6).

Correct the classpath of your application so that it contains a single, compatible version of org.elasticsearch.client.IndicesClient

Getting Error Like
An attempt was made to call the method org.elasticsearch.client.IndicesClient.create(Lorg/elasticsearch/action/admin/indices/create/CreateIndexRequest;[Lorg/apache/http/Header;)
Lorg/elasticsearch/action/admin/indices/create/CreateIndexResponse; but it does not exist. Its class, org.elasticsearch.client.IndicesClient, is available from the following locations:
jar:file:/audit.jar!/BOOT-INF/lib/elasticsearch-rest-high-level-client-6.7.0.jar!/org/elasticsearch/client/IndicesClient.class
It was loaded from the following location:
jar:file:/audit.jar!/BOOT-INF/lib/elasticsearch-rest-high-level-client-6.7.0.jar!
Please Help me out to solve this issue
Spring Boot 2.1.x uses Spring Data Elasticsearch 3.1.x which in turn is built against the libraries of Elasticsearch 6.2.2.
If you want to use Elasticsearch 6.8.5 you need to upgrade your Spring Data Elasticsearch version to 3.2.3 which is built against Elasticsearch 6.8.4.
I don't know if Spring Boot 2.1.0 can handle this in it's autoconfiguration, you might have to annotate your application with:
#SpringBootApplication(exclude = ElasticsearchDataAutoConfiguration.class)
and configure Spring Data Elasticsearch by yourself.

Spring Boot blows up when using solrj but not spring-boot-starter-data-solr

I am trying to port an existing Spring application across to Spring Boot. I am NOT using the spring-boot-starter-data-solr starter however I have apache solrj (5.0.0) on my classpath.
During startup the app blows up. It seems that spring boot sees the solr classes and assumes that I also have spring-boot-starter-data-solr on the classpath. In particular I get this error:
java.lang.IllegalArgumentException: #ConditionalOnMissingBean
annotations must specify at least one bean (type, name or annotation)
If I drop the solrj dependency and use spring-boot-starter-data-solr instead it is ok. However I don't need the spring-data-solr integration and doing so will force me to backport our app to the 4.7.x release of solr.
Is anyone aware of a workaround for this?
So it seems the problem was caused by spring boot's dependency on solrj 4.7.x whereas I am using 5.0.0
I fixed it by using
#SpringBootApplication(exclude = {SolrAutoConfiguration.class})
To tell boot to ignore the SolrAutoConfiguration completely.

Resources