spring boot compatibility issue with starter-web - spring-boot

I have just started working on a spring boot project and I am using stater web as one of its dependency, I used spring.io to create my project from scratch and from there itself I got
plugins {
id 'org.springframework.boot' version '2.1.6.RELEASE'
id 'java'
}
Now the problem I faced is my static content is not loading properly. I can see the static URL on browser's dev-tools with 200 OK message(which probably means a successful response of a get request) but still, the styles are not there as my CSS is not loading.
but if I use spring boot version 2.0.4 then everything works fine.
I went through release notes for spring boot version '2.1.6 RELEASE' but couldn't find anything except this
Auto-Configuration Exclusion
Exclusions are now applied consistently rather than only being applied locally. This applies to any exclusion defined on #EnableAutoConfiguration, #SpringBootApplication, #ImportAutoConfiguration or the spring.autoconfigure.exclude property.
which went over my head.
My question is if someone uses spring.io to create a project from scratch and in return gets all the dependencies compatible version from spring-boot starter parent and still the project for some reason like one mentioned above doesn't work then where should one go to find out what is the problem rather then changing version's.

Related

Selenium 4.1 and Spring boot Web driver version issue

I tried to migrate gradle project with spring boot from selenium 3 to selenium 4
(implementation 'org.seleniumhq.selenium:selenium-java:4.1.1')
But chrome, firefox and edge web drivers remains from selenium version 3
(org.seleniumhq.selenium:selenium-chrome-driver:3.141.59).
If I remove spring boot dependency from project, they updates to 4.1.1
Currently using gradle version "7.3.3".
Spring boot "2.6.3".
Spring dependency management "1.0.11.RELEASE".
Any ideas why this happens, I hoped that dependency hell dissapeared with spring boot creation)
Thanks in advance!
I have the same promble, I found in spring-boot-starter-parent, there is a spring-boot-dependencies in ~/.m2/repository/org/springframework/boot/spring-boot-dependencies/2.6.3/spring-boot-dependencies-2.6.3.pom, which declared <selenium.version>3.141.59</selenium.version> in properties, so you can try add
<properties>
<selenium.version>4.1.2</selenium.version>
</properties>
in your project pom.xml.
Spring Boot comes with a set of versions that are know to work together. But you can override them in your build script. In case of Gradle, add to build.gradle:
ext['selenium.version'] = '4.1.2'
It is because Spring Boot comes packed with a set of predefined dependecies that you can find here: https://docs.spring.io/spring-boot/docs/2.6.7/reference/htmlsingle/#appendix.dependency-versions
In this page, you will also find, how to change predefined version. In general, you need to add .version to your dependency name and, in case of multiple word names, you change spaces to dashes (not needed in case of selenium).
So, to change version to most recent, type in build.gradle ext['selenium.version'] = '4.4.0' at 0 indent level. (don't add it, say inside dependencies {})

spring-boot-starter-web with web application type NONE. Why?

I had never used CommandLineRunner before, because I've always written web servers. This time I'm building a microservice (CRON job) that wakes up, make some rest and db calls, and stops.
For this project, like others, initially I had the following dependency:
implementation "org.springframework.boot:spring-boot-starter-web:$springBootVersion"
Until I found out there is something called CommandLineRunner and, as I don't need a web server running, I can actually turn it off by .setWebApplicationType(WebApplicationType.NONE);
Now I'm wondering what's the point of including spring-boot-starter-web if we turn off its web server? I'm using Spring Boot framework to use its dependencies by default (things like jackson, etc.) and for its dependency management framework.
(Side note: I tried to move to sprint-boot-starter but there the following issue that I couldn't resolve, so I think I keep using spring-boot-starter-web :
Correct the classpath of your application so that it contains a single, compatible version of org.springframework.http.converter.json.Jackson2ObjectMapperBuilder)
We can see that spring-boot-starter-web includes:
spring-boot-starter
spring-boot-starter-json
spring-boot-starter-tomcat
spring-web
spring-webmvc
hibernate-validator
Looking at where Jackson2ObjectMapperBuilder is located we can see that it is in spring-web which is included by spring-boot-starter-json.
I suspect if you add spring-boot-starter-json you will be one step closer to running your service without the web server component.
Maven dependency analyzers can save quite a bit of trouble in the future by starting at the top and looking at what each of the POM files include.

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.

How to get version 4.0 spring jar on maven?

I searched spring on maven, and I find it at this page :http://mvnrepository.com/artifact/org.springframework/spring. The problem is I want to download 4.0 version but there is no 4.0 version in the chart.
Newer version of Spring can be found under group id org.springframework - Spring 4+
There is no reason to include all features of Spring Framework in one .jar. Spring is huge and you will probably won't use every feature of Spring. Including everything will cause unnecessary overhead. Pick what components you need add them to pom.xml and Maven will download them. If you found out later you need additional dependency just add it on the fly...
As an alternative you can use Spring Boot which will generate project for you with default set up. You can generate such a project using Spring Initializr Spring Boot Initializr. At the bottom click Switch to the full version. Pick what you need and hit generate project.

Gradle AspectJ plugin issue

I am facing a major issue with my Spring application since I migrated from Maven to Gradle: aspectj no longer works.
For instance classes annotated with #Configurable (which rely on aspectj) don't get their dependencies injected.
In order to replace the aspectj-maven-plugin, I tried using this plugin: from spring security code base but it seems it is not compatible with Gradle 2.1...
I also tried applying the solution described here: http://architects.dzone.com/articles/working-gradle-spring-aspects to no avail.
I am just curious to know how people who use Gradle + Spring manage to leverage aspectj...
Can anyone please kindly advise?

Resources