Handling different Spring Boot versions in custom Spring Boot Autoconfiguration projects - spring-boot

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?

Related

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.

Is it possible to write lib for projects using different versions of Spring?

I'm writing a lib for projects using different versions of Spring. The lib itself is based on Spring too ( more precisely, Spring Cloud Sleuth). For now, I use different versions for different projects( version1 for projects using Spring boot 2.0.x, version2 for projects using Spring boot 2.3.x, etc). Apparently, the maintenance took a lot of time and made some confusion. Is there a runtime mechanism like #Conditional but for dependencies?
First, check the Spring Cloud compatibility matrix. As you can see, different Spring Cloud versions support different Boot versions.
I would do the same for your library and maintain different versions of it.
Your can have optional dependencies on Sleuth and set things up using #Conditional annotations (e.g.: #ConditionalOnClass) but I would not recommend that.
Sleuth 2.2.x (Hoxton) uses Brave's API (btw 2.x is not supported anymore, you should upgrade). Sleuth 3.0.x (2020.0.x aka Ilford) and 3.1.x (2021.0.x aka Jubilee) have their own API and they abstract the tracer libraries away. You can use these interfaces/classes to detect the version and configure them differently but when you compile your library you can have classpath issues because you have 2.2.x, 3.0.x, and 3.1.x on your classpath.
Another thing you can do is modularize your library and put all of those things that does not depend on Spring into a "core" module then create smaller adapter/autoconfiguration/starter modules for every version of Spring Cloud you want to support.

Convert project from Spring framework to Spring boot

I have a set of projects in Spring framework and I have to Find the ones which can be converted to Spring boot.
Is there anything that is related to Spring framework and cannot be converted to spring boot ? In my research, I Could not Find something like that.
But does anyone know something, like a dependency, which would force the project to stay in Spring framework ?
Spring Boot uses the Spring Framework as a foundation and improvises on it. It simplifies Spring dependencies and runs applications straight from a command line. Spring Boot provides several features to help manage enterprise applications easily. Spring Boot is not a replacement for the Spring, but it’s a tool for working faster and easier on Spring applications. It simplifies much of the architecture by adding a layer that helps automate configuration and deployment while making it easier to add new features.
Most of the changes for migrating Spring Framework application to Spring Boot are related to configurations.This migration will have minimal impact on the application code or other custom components.Spring Boot brings a number of advantages to the development.
It simplifies Spring dependencies by taking the opinionated view.
Spring Boot provides a preconfigured set of technologies/framework to reduces error-prone configuration so we as a developer focused on building our business logic and not thinking of project setup.
You really don’t need those big XML configurations for your project.
Embed Tomcat, Jetty or Undertow directly.
Provide opinionated Maven POM to simplify your configurations.
Application metrics and health check using actuator module.
Externalization of the configuration files.
Good to refer this for migrating from Spring to Spring Boot application: https://www.javadevjournal.com/spring-boot/migrating-from-spring-to-spring-boot/

Spring Boot -1.5.3.Release Version - Enabled with Security Features?

I use Spring Boot - 1.5.3.Release Version for my project. Simply tested my demo application with Actuator and Dev-tools plugin from spring boot initializer site. (Hence I no longer needed to share my POM, as it is default).When I launch my application and try to hit the metrics End Point URL, I get this 401 Unauthorized status (image given below).
Following Options Tried to Bypass this exception
I excluded the SecurityAutoConfiguration on my main Class.
#SpringBootApplication
#EnableAutoConfiguration(exclude= {org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration.class})
public class MainConfig {
But the above option didn't work.
When I downgrade my Spring-Boot - 1.4.6.RELEASE Version, I didn't get the UnAuthorized Exception. My Application worked like a charm :-)
Questions
Is there any Specific Security Enhancements have been made in the latest release of Spring-Boot (1.5.3.RELEASE Version)?
If at all any enhancements made, let know the community on how to bypass such kind of exceptions?
I also, noticed that when using Spring-boot (1.5.3.RELEASE) it doesn't show any exceptions on startup, even though I have multiple main program in my IDE build path. Is that also an enhancement is spring-boot (1.5.3.RELEASE) version?
Kindly clarify.
From the Spring Boot 1.5 Release Notes:
If you’re upgrading a Spring Boot 1.4 application that doesn’t have dependency on Spring Security and you wish to retain open access to your sensitive endpoints you’ll need to set management.security.enabled to false.

adding spring-data-rest ontop of spring-data-jpa

i created a maven project, and added all dependencies i need.
i have some repositories using the spring-data-jpa, and i added some integration tests.
now i need to add ontop of it spring-data-rest, if i understand it is based on springmvc.
but all examples i found, i need to add spring boot to start the app.
i noticed also all new spring projects use spring boot.
this means that i have to learn and use it for my projects?
how can i use spring-data-jpa+spring-data-jpa with an existing servlet3 project
The reason all examples are written using Boot is that Boot is indeed the way you should start a new Spring project these days. It free's from a lot of the tedious work of setting up the infrastructure, finding dependencies in the right version etc.
To use Spring Data REST without Boot, simply add the necessary dependencies to your project. The easiest way to do this is to use the Spring Data Release Train BOM (which will help you pulling in the correct matching versions) along side the version-less dependency declarations for Spring Data REST WebMVC and - in your case - Spring Data JPA.
Then go ahead and either register RepositoryRestMvcConvfiguration as Spring bean (either through XML configuration or JavaConfig).
All of this is also documented in the reference documentation.

Resources