spring-boot-starter-parent AND spring version - maven

I'm developing a Java spring web service application. The application has a maven multi module layout, containing a webapp module - and a client module with a retrofit client.
I want to use the spring boot starter to manage my dependencies - and thus my webapp has the entry:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
</parent>
My client needs some Spring types - and this dependency would suufice:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.1.4.RELEASE</version>
</dependency>
Is there anyway to couple these versions?

You can use Spring Boot without the parent.
https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#using-boot-maven-without-a-parent
So you could add the dependency management to your own parent POM and both modules can use that as parent.

Related

java.lang.NoClassDefFoundError: Could not initialize class org.springframework.web.reactive.function.client.DefaultExchangeStrategiesBuilder

I am trying to use spring WebClient wc = WebClient.create(); in a non-Spring application, but it looks like DefaultExchangeStrategiesBuilder.DEFAULT_EXCHANGE_STRATEGIES returns null
causing error:
java.lang.NoClassDefFoundError: Could not initialize class org.springframework.web.reactive.function.client.DefaultExchangeStrategiesBuilder
at org.springframework.web.reactive.function.client.ExchangeStrategies.withDefaults(ExchangeStrategies.java:67)
at org.springframework.web.reactive.function.client.DefaultWebClientBuilder.initExchangeStrategies(DefaultWebClientBuilder.java:302)
at org.springframework.web.reactive.function.client.DefaultWebClientBuilder.build(DefaultWebClientBuilder.java:269)
at org.springframework.web.reactive.function.client.WebClient.create(WebClient.java:144)
I have added to my POM:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<version>2.6.5</version>
</dependency>
If your application is not a Spring Boot application and does not apply Spring Boot's dependency management, you should not use Spring Boot's starters.
Instead you should use Spring Framework's spring-webflux dependency directly, as well as a client library of your choice, like Reactor Netty, Jetty client, Apache HttpComponents...
You should also ensure that the Spring Framework BOM is applied to your project to avoid an incompatible mix of versions in your application:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>...</version>
<type>pom</type>
</dependency>

how to import spring-boot-starter-data-solr in spring boot 2.6.4

I'm studying using solr in springboot, I try the program in a book, the spring-boot-starter-parent version is 2.1.2.RELEASE in the book:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
while my spring-boot-starter-parent version is 2.6.4:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
and I add the solr dependency in pom.xml like this:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-solr</artifactId>
</dependency>
but the pom.xml shows error: The version cannot be empty, so I go to https://mvnrepository.com/ and find the latest spring-boot-starter-data-solr version is 2.4.13, so I add the solr dependcy like this:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-solr</artifactId>
<version>2.4.13</version>
</dependency>
the pom.xml has no error now, but the java program which import solr still not work, such as:
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
it cannot find any class about solr. I also try to download the spring-boot-starter-data-solr jar in https://mvnrepository.com/, and I import it locally, but I only find a META-INF document in the spring-boot-starter-data-solr jar downloaded, it doesn't have any classes
so how should I use solr in springboot?
The Spring Data for Apache Solr project has been discontinued. As a result, it was removed from the Spring Data release train in its 2021.0.0 release and from Spring Boot in its 2.5.0 release.
If you are using Solr directly, rather than via Spring Data, you can continue to do so. You will have to declare your Solr dependencies directly rather than relying on the Data Solr starter and you will have to configure Solr in your application rather than relying on Spring Boot's auto-configuration to do so.
solr-solrj is probably the updated alternative to the not updated spring-data-solr.

ServerRequest on SpringBoot 2.0.0.RELEASE

I recently moved my app. from Spring Boot 1 to Spring Boot 2 (2.0.0.RELEASE).
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
I want to import the class org.springframework.web.reactive.function.server.ServerRequest to get the Error Attributes from the interface
org.springframework.boot.web.reactive.error.ErrorAttributes;
but I got this error:
The import org.springframework.web.reactive.function.server.ServerRequest cannot be resolved
The Spring Boot Reactive Project spring-boot-web-reactive was merged into Spring Webflux with Spring 5.0
Make sure you have webflux Starter on your classpath:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webflux</artifactId>
</dependency>

Spring cloud Angel.SR3 not working for config client

I have an application using spring cloud server and spring cloud client. The spring cloud server has this in POM:
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<version>Angel.SR3</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
This version was upgraded from 1.0.2.BUILD-SNAPSHOT, it is good, but the problem happened for spring cloud client:
This is my current POM parent setting:
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<version>1.0.0.RELEASE</version>
</parent>
with this version, the env variable can be auto injected from config service, but once I change that to Angel.SR3, the auto injection failed immediately, can not inject environment variable at all.
Is there something wrong from spring cloud here?
After 1.0.0.RELEASE you need to include org.springframework.cloud:spring-cloud-starter-config.

Spring Boot with Spring HATEOAS Maven conflicts

It seems when I add the dependency for the spring-hateoas
<groupId>org.springframework.hateoas</groupId>
<artifactId>spring-hateoas</artifactId>
<version>0.13.0.RELEASE</version>
The Class below is no longer available on the classpath
org.springframework.web.bind.annotation.RestController;
I have tried to exclude various dependencies for the spring-hateoas but the APP no longer runs.
Has anyone had any luck running spring-hateoas within spring boot.
Absolutely no problem whatsoever. The #RestController annotation is still available and you shouldn't need to do any exclusion.
In case it helps, I'm currently using version 1.0.2 of Spring Boot:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.0.2.RELEASE</version>
</parent>
spring-boot-starter-web provides the #RestController:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
I don't define an explicit version for spring-hateoas in my pom.xml, but my build is pulling in 0.9.0.RELEASE:
<dependency>
<groupId>org.springframework.hateoas</groupId>
<artifactId>spring-hateoas</artifactId>
</dependency>
As a side note, I can see from the Eclipse POM editor, that Spring HATEOAS is defining dependencies on Spring 3.2.7. However the spring-boot-starter-parent project manages the versions up to 4.0.3. Can you see what version of Spring you are getting? Have you perhaps not used the spring-boot-parent as a parent project?

Resources