How to override the managed version of dependencies in Spring Boot - spring-boot

Spring Boot allows us to change the Java version using:
<properties>
<java.version>1.8</java.version>
</properties>
Is there any property to change the Java EE version or spring version in my Spring Boot pom.xml?
Currently I override the managed version using:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
Is there a better way to do this, like just setting properties?
Spring Boot 1.2.3 gives you Spring 4.1.6 by default.
How can I force Spring Boot to give me 4.1.5 instead, just by setting properties?

This in your pom.xml should do it:
<properties>
<spring.version>4.1.5.RELEASE</spring.version>
</properties>
All straight from the docs.
Before you go overboard overriding versions of dependencies, heed this advise (from the link above):
Each Spring Boot release is designed and tested against a specific set of third-party dependencies. Overriding versions may cause compatibility issues.

Related

How to upgrade the Spring Framework version from 4.0.5.RELEASE to 5.3.20

I want to upgrade the Spring Framework version from 4.0.5.RELEASE to 5.3.20 using Maven.
The versions in my pom.xml is
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java-version>1.8</java-version>
<org.springframework-version>4.0.5.RELEASE</org.springframework-version>
<org.springframework-security-version>3.2.5.RELEASE</org.springframework-security-version>
<org.apache.tiles-version>3.0.4</org.apache.tiles-version>
<org.hibernate-version>4.2.15.Final</org.hibernate-version><!-- 4.3.5.Final -->
<org.aspectj-version>1.6.10</org.aspectj-version>
<org.slf4j-version>1.7.7</org.slf4j-version>
<jackson.version>1.9.10</jackson.version>
</properties>
Can anybody help me in which all files I have to make changes.
Do I need to change other versions also in pom.xml to make it compatible with the new Spring version?
PS - I am new to Spring Framework. Would really appreciate any help.

Installing Spring Cloud CLI - which version with Spring boot 2.4.5

I want to install Spring Cloud CLI, but am not clear which version to use.
This Spring cloud page https://spring.io/projects/spring-cloud shows the compatible versions of Spring Cloud with Boot. For example
Release Train
Boot Version
2020.0.x aka Ilford
2.4.x
Hoxton
2.2.x, 2.3.x (Starting with SR5)
I have Spring boot 2.4.5 installed. This implies I should use Spring cloud version 2020.0.x
If I check https://repo.spring.io/release/org/springframework/cloud/spring-cloud/ I do not see a version 2020.0.x
If I use
spring install org.springframework.cloud:spring-cloud-cli:2020.0.1
I get an error "could not find artifact org.springframework.cloud:spring-cloud-cli:jar:2020.0.1 "
If I use
$ spring install org.springframework.cloud:spring-cloud-cli:2.2.0.RELEASE
it appears to install correctly, however I get errors when I try to run commands like
$ spring cloud eureka.
My question is what version of cloud should I install with spring boot v 2.4.5 ?
2020.0.x is the version of the Spring Cloud release train, not of the single modules itself. The release train version can be used, if you use the Spring Cloud BOM to include the dependencies, as described here: https://spring.io/projects/spring-cloud.
This would look similar to this then:
<properties>
<spring.cloud-version>Hoxton.SR8</spring.cloud-version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring.cloud-version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
If you only want to use single modules, then you need to find out, which versions belong to the release train, by either looking in the respective spring-cloud-dependencies POM (https://repo.spring.io/release/org/springframework/cloud/spring-cloud-dependencies/2020.0.2/), or in the release notes, which also contain the module versions: https://spring.io/blog/2021/03/18/spring-cloud-2020-0-2-aka-ilford-is-available
So in your case, the proper version for spring-cloud-cli would be 3.0.2.

Maven control version of transitive dependencies of Spring Boot

I have a simple spring boot app that I am trying to add spring cloud consul to. Spring cloud consul relies on a newer version of spring boot. In my POM I have specified version 1.3.5.RELEASE for all my spring boot artifacts.
The problem is that, even though version 1.3.5 is specified for spring-boot-starter-web it still downloads dependencies with version 1.2.3
Is there a way to have maven get the 1.3.5.RELEASE for ALL spring boot artifacts, including transitive dependencies? I know I can explicitly list them all, but is there a better way?
Here is the POM depenency view from eclipse:
Yes, simple use correct parent:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.6.RELEASE</version>
<relativePath/>
</parent>
and remove versions from spring boot dependencies.

Maven dependencies needed for Jersey 2.x (2.6)

I'm trying to migrate from Jersey 1.x (1.2) to 2.x (2.6), I have trouble identifying the exact maven dependencies, jersey documentation is not comprehensive enough, it doesn't mention what maven dependencies are needed for the new version.
Does anyone have comprehensive list of maven dependencies needed for Jersey 2.x (2.6)?
Jersey doc
https://jersey.java.net/documentation/latest/migration.html#mig-1.x
For a servlet environment, the only dependency you need is
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.6</version>
</dependency>
This will pull in all you need. If you are in a servlet 2.5 environment, then you would use this instead
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.6</version>
</dependency>
Further information about 2.5 servlet, can be seen here
Alternatively, you could create a project from a Maven archetype, as seen here
UPDATE
Just as a note, the significance of using Jersey 2.6 is that it is the last version to support Java 6. If this is not a requirement for you, I would recommend using the latest version.

What replaces FacesContextUtils in Spring 3?

We just upgraded from Spring 2.5 to Spring 3.0.7. The class:
org.springframework.web.jsf.FacesContextUtils
doesn't appear exist in 3.0.7. We are trying to call:
FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance()).getBeansOfType(type);
Is there a replacement in Spring 3?
This class also exists in Spring 3.0.7, maybe you missed a jar or downloaded a different release?
You can use the following maven dependency:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.web</artifactId>
<version>3.0.7.RELEASE</version>
</dependency>
You can also get the jar from the spring repo.
If this doesn't help you may update your question with the stacktrace of the error msg.

Resources