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

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.

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 .

Is it possible to use Kafka with Spring 4.1.0.RELEASE?

I'm working on a legacy project with Spring Version 4.1.0.RELEASE (no Spring Boot). Is there a way to integrate Kafka to the project? We need to consume and produce messages.
All I found on the internet about Spring + Kafka was about newer Spring versions and/or Spring Boot. Updating the project is unfortunately not an option. There is a parallel updating project for the application, but we need a short-time solution.
I tried to use spring-kafka 1.3.11.RELEASE, but I get an error while starting the application.
Caused by: java.lang.ClassNotFoundException: org.springframework.core.MethodIntrospector
I found out that update to a newer Spring version would fix that. But as I said, updating Spring is not an option in this project context.
kafka-clients alone does not depend on Spring. You are not required to use spring-kafka , spring-integration, spring-cloud-streams, etc. dependendencies to "use Kafka with Spring", so if you don't mind wiring in the Kafka clients by yourself, then just start with the raw client library.

Changes To Spring #Autowired From Spring Boot 2.5.6 to 2.6.2

We have a Spring Boot App packaged as a war file and deployed on Wildfly. When I update the Spring Boot version from 2.5.6 to 2.6.2, I see lots of exception with Spring Autowire of variables. The problems being reported are circular dependency.
Has something changes with new version of Spring that changes how the autowiring works? I tried to research and can find no mention to changes in that area.
Thanks
The thing is that with the new Spring Boot version, circular dependencies are not allowed by default. Check the release notes.
You can get back to the previous behaviour setting the following configuration:
spring.main.allow-circular-references: true
However, I would suggest you revisit the application design.

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.

Handling different Spring Boot versions in custom Spring Boot Autoconfiguration projects

In custom Spring Boot Autoconfiguration projects I usually have some dependencies which are marked as optional. As I need them for compilation, but expect users of my autoconfig to include them manually in their own POM, or they will be provided by the Spring Boot dependencies.
How do I ensure that users of different Spring Boot versions can use my autoconfig without dependecy/version problems?
I see two non-optimal solutions; are there more?
Hoping that the API stays the same
Just hope that the API of my dependencies stays stable over minor version changes, so that if I developed and compiled my Autoconfig e.g. with Spring Boot 1.4.x, the API which I used is still the same with 1.5.x, etc.
I then wouldn't necessarily expect it to work e.g. for Spring Boot 2.x, and would put a corresponding note into the readme.
Explicitly tracking each Spring Boot version
Explicitly build a version for at least each minor Spring Boot version, but possibly even for each Patch version? Who knows when a breaking API change could happen. I would then need to document for which exact Spring Boot version my autoconfig is intended. But this is a lot of work.
Of course Spring Boot's own autoconfig project is developed in lockstep with Spring Boot, so that any problems will be fixed in the same release.
But my own autoconfig might have been developed once and not expect many changes afterwards. How do I ensure that my autoconfig keeps working as long as possible even as the "users" of my autoconfig are updating their Spring Boot version dependencies?

Resources