Spring Boot BOM for non boot spring project - java

I'd like to use spring boot specific BOM for my non-boot spring project. Is it acceptable to include spring-boot-dependencies or platform-bom and what's better?
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>...</version>
<type>pom</type>
<scope>import</scope>
</dependency>
or
<dependency>
<groupId>io.spring.platform</groupId>
<artifactId>platform-bom</artifactId>
<version>...</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Thanks.

Both are valid approaches.
To quote the Spring IO Platform documentation :
Spring IO Platform builds on top of Spring Boot
So, they provide what you search for a non spring boot application : a set of consistent dependencies and some specific beans provided by Spring Boot.
Now, personally, I would chose org.springframework.boot:spring-boot-dependencies as Spring Boot is mature, have an important and active community and is often updated.
See the spring-boot github.
It is not the case of the spring-io/platform.

Related

Which Spring Cloud AWS version should be used with Spring Boot 3?

I am trying to make SqsListener work but I can't with Spring Boot 3, it simply doesn't receive anything. When I change Spring Boot version back to 2.X everything's work perfectly.
I am using 2.4.2 version of Spring cloud:
...
<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-starter-aws-messaging</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-aws-dependencies</artifactId>
<version>2.4.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Can you please point me to the correct version of spring cloud?
Would I need to use milestone version for that?
It doesn't work as version 2.4.2 of spring-cloud-starter-aws-messaging relies on spring.factories for Spring Boot autoconfiguration, but the support for that has been removed in Spring Boot 3.0.0. See https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.0-Migration-Guide#auto-configuration-files.
You can enable the auto configuration by creating the following file
src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
# content
io.awspring.cloud.autoconfigure.messaging.SqsAutoConfiguration
But, it probably won't work anyway as spring-cloud-aws also relies on classes from Spring Messaging that were deprecated and removed in Spring 6 (which is used in Spring Boot 3), specifically org.springframework.messaging.handler.annotation.support.PayloadArgumentResolver.
You'll have to wait for Spring Cloud AWS to support Spring Boot 3. They are working on Spring Cloud AWS 3.0.0, but I don't think it has a release date yet. https://github.com/awspring/spring-cloud-aws

What is the maven dependency to use Jackson2ObjectMapperBuilderCustomizer? For a spring mvc project

I have a Spring MVC project which does NOT USE spring-boot.
Im trying to use Jackson2ObjectMapperBuilderCustomizer in my appConfig class to configure a default date format.
I have these two dependencies in already but I'm still getting an error on the ObjectMapper? I am using spring version 4. All the examples for using the Jackson2ObjectMapperBuilderCustomizer are using spring boot which seems to not need need a dependency
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.8</version>
</dependency>`
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.9.8</version>
</dependency>`
The class is only part of Spring Boot dependencies. If you are determined to not use any Spring Boot dependencies, you will have to look for alternatives, otherwise you can use the following:
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-autoconfigure -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>1.2.2.RELEASE</version>
</dependency>
Add jackson-datatype-jsr310 dependency . its an alternative for non spring boot projects.
https://mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-jsr310/2.10.1

How to determine the <parent> dependency for a set of springframework dependencies

I like to know if below is possible and how.
I was following a tutorial for spring boot and it was mentioned there we can have a parent dependency.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent>
And then define the dependencies without the version number.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
This will add the dependencies version 1.5.6.RELEASE of spring-boot-starter and spring-boot-starter-web in to the projects dependencies.
Just like that I want to find what is the <parent> code snippet for the following dependencies I need to add in to a new project.
Dependencies in <groupId>org.springframework</groupId>. I need to use the version 4.3.9.RELEASE.
spring-context
spring-jdbc
spring-test
Thanks!
If you are using Spring Boot then these three dependencies will be provided for you by the following starters:
spring-test will be provided by spring-boot-starter-test
spring-context will be provided by spring-boot-starter-data-jpa
spring-jdbc will be provided by spring-boot-starter-jdbc
So, with the following parent:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent>
... if you add these dependencies:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
... then you will get
spring-context
spring-jdbc
spring-test
However, Spring Boot 1.5.6.RELEASE depends on v4.3.10.RELEASE of those core Spring libraries not 4.3.9.RELEASE as suggested in your question. Typically, you would accept Spring's curation of dependencies so if Sping provides 4.3.10.RELEASE then either (a) you should use that version or (b) downgrade Spring Boot toa version which provides 4.3.9.RELEASE.
Read on for details on how to identify the correct starter for a given curated library ...
The spring-boot-starter-parent is a special starter that provides useful Maven defaults and a dependency-management section which defines numerous dependencies which you might want to use in your POM. These dependencies are often referred to as "curated" or "blessed" and since they are defined in a dependency-management section somewhere in the maven hierarchy you can refer to them in your POM without a version tag (i.e. they inherit the version from the dependency-management section entry.)
You can see the spring-boot-starter-parent POM here and peeking inside you can see that it references the spring-boot-dependencies POM here.
Looking at your question you mentioned that you can declare a dependency like so ...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
... this is because the spring-boot-dependencies POM declares the following:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${revision}</version>
</dependency>
So, the parent and the starters are just a means of wrapping up dependency declarations and making them easier for application developers to use. The Spring docs summarise this as:
Starters are a set of convenient dependency descriptors that you can include in your application. You get a one-stop shop for all the Spring and related technologies that you need without having to hunt through sample code and copy-paste loads of dependency descriptors. For example, if you want to get started using Spring and JPA for database access, include the spring-boot-starter-data-jpa dependency in your project.
However, this does not mean that all dependencies must be declared via parents or starters so, if you are not using Spring Boot then you can declare a dependency without using a parent or a starter and what you have described in your question (declaring dependencies on 3 core Spring libraries) can be safely covered by simply depending on those 3 libraries explicitly. For example, just add the following to your your pom.xml:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.9.RELEASE</version>
<scope>test</scope>
</dependency>
Since you are going though the tutorials I'm assuming you are new to spring.
The folks at spring were nice enough to setup a site that generates projects.
It is very easy to use. I recommend trying that while learning. Download a few apps with the dependencies you want and look at how they are set up.
Once you are comfortable and want to dive deeper, read #glytching's answer again, it is very good.
Use spring-framework-bom if you don't use Spring Boot and need Spring Framework dependencies only:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>4.3.9.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
In such case dependency would be without version was specified:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
Also, yet another option exists if you use Spring Boot but you don't want to use spring-boot-starter-parent as parent artifact:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.5.9.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
See Spring Boot docs for more details. An important note from the docs:
Each release of Spring Boot is associated with a base version of the Spring Framework so we highly recommend you to not specify its version on your own.
It means that you should use Spring Framework version is defined for Spring Boot.

how to make a spring boot project child module of a parent

I would like to create two modules (dao and api) under this parent project. Module api would be restful api using Spring Boot. Since spring boot projects all have spring-boot-starter-parent as the parent module, how do I make it a child module under another parent? My understanding is Java projects can only have one parent.
You can use DependencyManagement instead of parent
Not everyone likes inheriting from the spring-boot-starter-parent POM. You may have your own corporate standard parent that you need to use, or you may just prefer to explicitly declare all your Maven configuration
<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.3.3.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Source: Spring Boot Documentation

Paho MQTT vs MQTT paho spring integration

While I was fixing some issues in my client within an application using paho and spring framework, I discovered the spring MQTT integration. I'm not sure if this fix my problems, and I not even sure what is this.
Could someone explain what is the difference of using this together?
Do spring framework bring errors into paho that the integration solve?
or is save enough use this two technologies separate?
The dependencies used by me are:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.2.5.RELEASE</version>
</dependency>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.2.5.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
and :
<dependency>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<groupId>org.eclipse.paho</groupId>
<version>1.0.2</version>
</dependency>
The integration of the dependency below it will be quite painful. I want to know if there is any advantage on doing this.
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-mqtt</artifactId>
<version>4.0.4.RELEASE</version>
</dependency>
Thank you all!
Spring Integration is sub framework in Spring eco system which allows to configure Enterprise Integration Patterns easily for Enterprise Application Integration.
It is good if you want to do processing of data with Source, Filter, Accumulator, Processor, Sink kind of a architecture with highly cohesive and loosely coupled components.
It is ideal to use where you have multiple systems speaking different protocols together which needs to integrated to with other systems without much fuss.

Categories