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

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 .

Related

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.

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 cloud starter task : Not able to work on Spring boot 2.x

I was trying to make spring boot batch application(2.0.0.RC1) work with Spring cloud starter task(2.0.0.M2).
Getting a range of errors while making Spring cloud starter task work with spring boot 2.x batch application.
I was able to run batch applicationspring-boot-starter-parent(1.5.10.RELEASE) with Spring cloud starter task(2.0.0.M2) successfully.
Here is the screeenshot
But when I tried Spring cloud starter task(2.0.0.M2) with spring boot 2.0.0.RC1, I am getting following error.
com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Could not resolve type id '' into a subtype of [simple type, class java.lang.Object]:
Here is the screenshot of the same.
So I decided to downgrade Spring boot to 2.0.0.M7.Alas I am getting a different exception.
java.lang.IllegalStateException: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#61f78561 has been closed already.
Why this exceptions happens?Any help/guide would be appreciated.
There have been quite a few upstream changes in Spring Boot, which caused side effects in Spring Cloud Task's 2.0.
We have had a all of them resolved (some in Boot itself) - see here.
We are targeting a 2.0 M3 release this week, so until that is done, perhaps you could try building 2.0 BUILD-SNAPSHOT locally. If you see any other anomaly, please let us know.

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.

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