The requirement is to use spring boot version 2.2.6.RELEASE however the tomcat version should be 9.0.37.
I tried to do it by excluding the tomcat starter from the spring-boot-starter-web depdendency like so :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
And added the spring-boot-starter-tomcat separately which has the 9.0.37 tomcat version :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>2.3.2.RELEASE</version>
</dependency>
However even after doing so the version is not override and the following gets used :
Mar 11 2020 09:31:38 UTC
Apache Tomcat/9.0.33
9.0.33.0
Do we need to do anything else to override the tomcat version?
Is it possible to override it by excluding started?
Update:
The parent pom is a corporate parent pom and not the spring-boot-starter-parent. As per one of the answers we can simply override the tomcat.version property however my effective pom doesn't show it.
If you're not inheriting from spring-boot-starter-parent I can only guess that you import spring-boot-dependencies in your dependencies management somewhere.
The documentation covers what you need to do to override the tomcat version. Each tomcat artifact should be listed with the overridden version, before you imports spring-boot-dependencies. The list of artifacts can be found in spring-boot-dependencies.
Using a different version of the starter is wrong (you can't mix two Spring Boot versions in the same app) and will have no effect since dependency management is in control anyway. In other words, you'll get spring-boot-starter-web version 2.3.2.RELEASE indeed but all the artefacts that it brings will be managed by the dependency management (the tomcat version defined by version 2.2.6.RELEASE).
In that particular case of yours, upgrading to 2.2.9.RELEASE could also be an option as it provides dependency management for the tomcat version that you need.
Well, this has been already answered.
For you, as you are using maven, you need to override the properties set in parent Spring pom.
<properties>
......
<tomcat.version>your_version</tomcat.version>
......
<properties>
For gradle, it is simple as
ext['tomcat.version'] = '8.5.34'
in your main build.gradle
Source: How to change embedded tomcat's version in existing spring boot app?
Related
I need to load a JNDI resource located in a JBoss server. For this, I am using a jnp-client library:
<dependency>
<groupId>jboss</groupId>
<artifactId>jnp-client</artifactId>
<version>4.2.2.GA</version>
</dependency>
The problem is that as soon as I include this dependency in my pom.xml, the Spring application gets stuck at the start time without any message. Not a single line of logs, like if it is trying to load something forever. The main is not even invoked. Removing this dependency the application runs but I get an expected:
ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
Which is normal because I have removed the dependency that includes this class.
Any clue?
I have tried all version of jnp-client or jbossall-client that also includes this NamingContextFactory
EDIT:
It is the mix of these two dependencies that unfortunately are inherited from required dependencies:
<dependency>
<groupId>org.jboss.naming</groupId>
<artifactId>jnp-client</artifactId>
</dependency>
and spring-webmvc inside
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
If I run with
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</exclusion>
</exclusions>
</dependency>
It works fine.
Now, if I exclude the jnp-client I cannot access the JNDI resource, but if I remove the spring-security-web I cannot access the REST endopoints this service exposes.
EDIT2:
So I thought it could be two classes interfering with each other and I started the java process with -verbose. This is what I found.
org.springframework.boot.context.config.ConfigFileApplicationListener$Loader$$Lambda$165/0x00000001002d8440
source:
org.springframework.boot.context.config.ConfigFileApplicationListener$Loader
[389.020s][info][class,load]
org.springframework.boot.context.config.ConfigFileApplicationListener$Loader$$Lambda$166/0x00000001002d8840
source:
org.springframework.boot.context.config.ConfigFileApplicationListener$Loader
[558.011s][info][class,load]
org.springframework.boot.context.config.ConfigFileApplicationListener$Loader$$Lambda$167/0x00000001002d8c40
source:
org.springframework.boot.context.config.ConfigFileApplicationListener$Loader
[558.012s][info][class,load]
org.springframework.boot.context.config.ConfigFileApplicationListener$Loader$$Lambda$168/0x00000001002d9040
source:
org.springframework.boot.context.config.ConfigFileApplicationListener$Loader
From time to time the application prints, only in verbose, this ConfigFileApplicationListener$Loader
EDIT 3:
It seems that the problem is TimedSocketFactory inside the jnp-client. Somehow, just by having this class inside the jnp-client dependency, the Spring application is blocked and never starts. Removing this from the jnp-client allows the application to start. Of course, it fails later because the JNDI cannot connect to the server.
I try to add Spring Data REST dependency using this dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
After adding this dependency I catch an exception - java.lang.NoSuchMethodError: org.springframework.plugin.core.PluginRegistry.of(Ljava/util/List;)Lorg/springframework/plugin/core/PluginRegistry;
And the Action suggestion: Correct the classpath of your application so that it contains a single, compatible version of org.springframework.plugin.core.PluginRegistry
I tried to add this dependency to fix the problem:
<dependency>
<groupId>org.springframework.plugin</groupId>
<artifactId>spring-plugin-core</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
But it didn't help me.
How could I fix this problem?
I use Spring Boot version - 2.2.7.RELEASE, Maven version - 3.3.9
I have a project which uses the latest version of Hibernate (let's say v2.0). I'm using it all around the project. But my project also uses some dependency (let's say MySQL Connector), which uses Hibernate (let's say v1.0). So in my pom.xml I would have something like:
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>Hibernate</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.mysql</groupId>
<artifactId>MySQLConnector</artifactId>
<version>3.7</version>
</dependency>
</dependencies>
In the end, when I compile my project, the version of Hibernate downloaded and used is v1.0 because MySQLConnector needs this one. Is there a way to specify some version of a dependency that will be used only by one of my dependencies and the rest of the code to use another version? So something like:
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>Hibernate</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.mysql</groupId>
<artifactId>MySQLConnector</artifactId>
<version>3.7</version>
<somemagicaltag>
<groupId>org.hibernate</groupId>
<artifactId>Hibernate</artifactId>
<version>1.0</version>
</somemagicaltag>
</dependency>
</dependencies>
Thus allowing MySQLConnector to use the older version of Hibernate if it likes it, but the rest of my code to use the newer, more updated version of Hibernate?
Is there a way to specify some version of a dependency that will be
used only by one of my dependencies and the rest of the code to use
another version?
No. There can be only one. So in your case either 1.0 or 2.0 (usually using newer version makes more sense). Which version is used depends on the order of dependencies in pom.xml which use such transitive dependency: Why order of Maven dependencies matter?
You can also define which version will be used by specifying such dependency (this overrides transitive dependency version) or by defining such dependency either in dependencyManagement tag: Differences between dependencyManagement and dependencies in Maven or by using BOM mechanism: Maven BOM [Bill Of Materials] Dependency
In all "normal" cases, the dependency that you declare wins against the ones that come transitively. So I would assume that in your setup, you get version 2 of hibernate (and nothing else). You can find out by calling mvn dependency:list.
You cannot load the same class twice in different versions, so normally, you cannot have two versions of hibernate in the same project. There are approaches around this (using the Maven shade plugin), but this should be the exception. Try to make your own code and your dependencies work with the same version of hibernate.
You can skip downloading that default artifact which is getting downloaded by Maven.
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>Hibernate</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.mysql</groupId>
<artifactId>MySQLConnector</artifactId>
<version>3.7</version>
<exclusions>
<exclusion> <!-- declare the exclusion here -->
<groupId>org.hibernate</groupId>
<artifactId>Hibernate</artifact>
</exclusion>
</exclusions>
</dependency>
</dependencies>
I am working with a Maven project where I have spring framework dependency version 3.2.3.RELEASE and I have to import this project into many others but in some of them I am using spring 4.
How can I exclude this dependency (spring 3) only in case that the project that uses mine has the same or newer version of spring and in those who hasn't use mine?
One thing you can do is to manually exclude unwanted dependencies:
<dependency>
<groupId>com.your.project</groupId>
<artifactId>project-name</artifactId>
<version>1.0.0</version>
<exclusions>
<exclusion>
<artifactId>org.springframework</artifactId>
<groupId>spring-core</groupId>
</exclusion>
</exclusions>
</dependency>
But that can get quite verbose.
It may help if you elaborate a bit more on the problem description as it is not clear to me what exactly are you trying to solve or achieve.
For instance if you include a dependency A which has a dependency B in version 1.0 and then you include B in your pom in 1.1 Maven will use only 1.1. I recommend reading up on it a bit here: https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Transitive_Dependencies
I'm starting a new project with Spring Batch 2.1.6.RELEASE and I use Maven for depemdency management.
By default, it imports spring framework 2.5.6, but I'd like to use 3.0.5.RELEASE instead.
This post says it's compatible, but I don't know how to declare that in my maven pom file.
I tried just putting the dependencies for spring-core, spring-beans and spring-context versions 3.0.5.RELEASE, but that adds the libraries to the project without removing the 2.5.6 version.
I had a look at spring-batch-parent pom file, and there is a profile called "spring3" that uses the spring version I want. How do I activate a profile in my project's pom file ?
Thanks in advance,
Philippe
You can exclude the transient dependency on Spring Framework v2.5.6 of Spring Batch by using the dependency exclusions element of the spring-batch dependency in maven. Something like...
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-core</artifactId>
<version>2.1.6.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<!-- Other exclusions here -->
</exclusions>
</dependency>