java.lang.ClassNotFoundException: jakarta.servlet.http.HttpSessionContext with Spring Boot 3 and Jetty server - spring

I community, I'm trying to run a small example with Spring boot 3 and Jetty server before upgrading the production code but I'm getting this error java.lang.ClassNotFoundException: jakarta.servlet.http.HttpSessionContext and the services does not start. This is my Gradle config.
plugins {
id 'java'
id 'idea'
id 'org.springframework.boot' version '3.0.1'
id 'io.spring.dependency-management' version '1.1.0'
}
idea {
module {
downloadJavadoc = false
downloadSources = false
}
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-jetty'
implementation('org.springframework.boot:spring-boot-starter-web') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
}
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
useJUnitPlatform()
}
and the dependeincies.
HttpSessionContext class no longer exists but somehow, the latest version Jetty still depends on it.
I'm expecting to make it run with Jetty without migrating to another server.

As Jaokim Erdfelt already mentioned, Spring Boot 3 rely on Jakarta Servlet 6.0.0 (see https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.0-Release-Notes) and the spring-boot-starter-jetty includes Jetty 11 which is build on Jakarta Servlet 5.0.0 (see https://java.libhunt.com/jetty-project-changelog/11.0.0). So this is an Issue in the starter itself.
To use jetty you have to downgrade the jakarta-servlet version (see https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.0-Migration-Guide#jetty) setting
ext["jakarta-servlet.version"] = "5.0.0"

Spring 3 is for Servlet 6 which is available in Jetty 12+

Related

Could not resolve: org.thymeleaf.extras:thymeleaf-extras-springsecurity6:3.1.0.RELEASE

what is the problem, i just changed group name here, i get could not resolve for springsecuriy extras
i can't see why
plugins {
id 'java'
id 'org.springframework.boot' version '3.0.0'
id 'io.spring.dependency-management' version '1.1.0'
id 'org.hibernate.orm' version '6.1.5.Final'
id 'org.graalvm.buildtools.native' version '0.9.18'
}
group = '*********'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6'
runtimeOnly 'org.mariadb.jdbc:mariadb-java-client'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
}
tasks.named('test') {
useJUnitPlatform()
}
hibernate {
enhancement {
lazyInitialization true
dirtyTracking true
associationManagement true
}
}
Could not resolve all files for configuration ':compileClasspath'. > Could not resolve org.thymeleaf.extras:thymeleaf-extras-springsecurity6:3.1.0.RELEASE. Required by: project : > Could not resolve org.thymeleaf.extras:thymeleaf-extras-springsecurity6:3.1.0.RELEASE. > Could not parse POM repo.maven.apache.org/maven2/org/thymeleaf/extras/… > Could not find org.springframework.security:spring-security-bom:6.0.0-RC2
I tried nothing it is made by spring initializer and boot version 3.0.0
Thymeleaf 3.1.1 is released now, pls use
implementation("org.thymeleaf.extras:thymeleaf-extras-springsecurity6:3.1.1.RELEASE")
instead of
implementation("org.thymeleaf.extras:thymeleaf-extras-springsecurity5")
I resolved problem by changing gradle build
i replaced repositories with this
repositories {
mavenCentral()
maven { url "https://repo.spring.io/milestone"
content {
// Thymeleaf uses 6.0.0-RC2 of Security's bom in its dependency management
includeModule("org.springframework.security", "spring-security-bom")
}
}
}
I hope it help others

Gradle Spring Boot Dependency Not found Multi Module Project

I am trying to set up multimodule project
RootProject Settings
rootProject.name = 'Abc'
include 'catalog'
include 'catalog-common'
Root Project Abc/build.gradle
plugins {
id 'org.springframework.boot' version '2.7.3' apply false
id 'io.spring.dependency-management' version '1.0.13.RELEASE'
id 'java'
}
subprojects {
group = 'com.abc'
apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'
sourceCompatibility = 1.8
targetCompatibility = 1.8
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
dependencyManagement {
imports {
mavenBom org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES
mavenBom "org.springframework.cloud:spring-cloud-dependencies:2021.0.3"
}
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
}
}
Module catalog-common
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation('org.springframework.boot:spring-boot-starter-validation')
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
Module Catalog
plugins {
id 'org.springframework.boot' version '2.7.3'
}
dependencies {
implementation project(':catalog-common')
}
in Catalog Project it is expecting again to define spring dependencies but where as I am able to access java static classes
Please help
It looks like your catalog-common is a kind of "library" module, consumed by other sub-projects (catalog and maybe others). If so, you should use the Java Library plugin which can be used for this purpose. You will then need to configure all dependencies you want to "inherit" in consumer projects using api configuration instead of implementation. Dependencies declared in implementation will not leak into consumer projects, this is the expected Gradle behavior.
In you example, catalog-common build script should look like:
plugins {
id("java-library")
}
dependencies {
// choose between api or implementation, depending on the scope you want for each dependency
api 'org.springframework.boot:spring-boot-starter'
api 'org.springframework.boot:spring-boot-starter-actuator'
api 'org.springframework.boot:spring-boot-starter-web'
implementation('org.springframework.boot:spring-boot-starter-validation')
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
implementation 'org.springframework.boot:spring-boot-starter-test'
}
Please note that it seems a bit strange to configure some of the Spring dependencies like actuator in this common library: this should declared only in the main "application" project ( catalog in your case), unless you want to implement some common code depending on actuator in the catalog-common module.

getting springboot to support groovy 4.0 (apache packaging) | needed 3.0.0-M2 and more

spring-boot > 2.3.1 will grab groovy-bom from codehaus instead of org.apache.groovy packaging, even if you declare org.apache.groovy dependendices
I found this means spring-boot > 2.3.1 will not build groovy 4.0
even spring initializr bakes this in... because when you go springboot 2.6.7, initializr is using groovy packaging from org.codehaus. so that limits 2.6.7 to use groovy 3.0.10, as that's the cutoff for groovy to show up in org.apache packaging. and groovy 4.x uses apache packages.
here's the gradle initializr created from this URL
plugins {
id 'org.springframework.boot' version '2.6.7'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'groovy'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
implementation 'org.codehaus.groovy:groovy'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
useJUnitPlatform()
}
Support for Groovy 4 is coming in Spring Framework 6 and Spring Boot 3. It’s currently available in Spring Boot 3.0.0-M2 which is published to https://repo.spring.io/milestone.
you 1st have to change settings.gradle to add the following:
pluginManagement {
repositories {
maven { url 'https://repo.spring.io/milestone' }
gradlePluginPortal()
}
}
Then I had to modify my build.gradle as follows:
plugins {
// id 'org.springframework.boot' version '2.6.7'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'groovy'
}
plugins {
id 'org.springframework.boot' version '3.0.0-M2'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = javaSrcVersion
targetCompatibility = javaClassVersion
repositories {
mavenCentral()
maven { url("https://repo.spring.io/milestone/")}
}
dependencies {
runtimeOnly('com.h2database:h2')
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
// implementation 'org.codehaus.groovy:groovy'
implementation("org.apache.groovy:groovy:${groovyVersion}")
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation('com.google.code.findbugs:jsr305:latest.integration')
implementation group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'
implementation group: 'jakarta.persistence', name: 'jakarta.persistence-api', version: '3.1.0'
implementation group: 'commons-io', name: 'commons-io', version: '2.11.0'
testImplementation("org.testng:testng:${testNgVersion}")
}
tasks.named('test') {
useJUnitPlatform()
}

Spring Boot plugin was not found

I have an issue with gradle project
My build.gradle
buildscript {
ext {
springBootVersion = '2.1.8.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath(
"org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
plugins {
id 'org.springframework.boot' version '2.1.8.RELEASE'
}
apply plugin: 'org.springframework.boot'
group = 'com.demo'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
runtimeOnly 'mysql:mysql-connector-java'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
}
When I try to run build.gralde, I'm getting error
Plugin [id: 'org.springframework.boot', version: '2.1.8.RELEASE'] was not found in any of the following sources:
Gradle preferences in IDEA
I can't understand, what is the problem, I've generated project with Spring Initializer
I think, I've got the problem.
You just need to turn off "Offline Mode" and it will download it from repo
It's in the right side of the Intellij IDEA
A possible explanation is that by configuring explicitly the buildscript.repositories, you no longer have the default gradlePluginPortal().
Not all plugins are available on Maven Central for example.

Cloud client config application do not get properties from Config Server Spring boot

I have a web application and I want to use Server Configuration from Spring Boot.
Both applications are located on localhost machine. I have made first two applications from scratch and they worked together, but when i use the client that has many dependencies in it (not just the cloud-config and web dependency) it is not working anymore. How do I know? I have a variable in properties file in server and i try to use it in my client with #Value("${atena}")
and error appears java.lang.IllegalArgumentException: Could not resolve placeholder 'atena' in value "${atena}".
The following image is my server config application.
The main class from server has the following annotation #EnableConfigServer
In atena-config.yml I have only the variable name:
atena: 'Hellllloooooo'
bootstrap.yml content
server:
port: 9000
spring:
profiles:
active: native
and build.gradle dependencies:
dependencies {
implementation 'org.springframework.cloud:spring-cloud-config-server'
runtimeOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
I am sure the server it is correct, something is wrong with my client.
--------------------> Client side
I have a restcontroller:
#RestController
#RequestMapping("/songs")
public class SongController {
#Value("${atena}")
String variable;
#GetMapping(value="/check-from")
public String viewVariable(){
return variable;
}
}
in which I am trying to get the variable from server config.
bootstrap.yml from client
spring:
application:
name: atena-config
cloud:
config:
uri: http://localhost:9000
And lastly the build.gradle from client:
plugins {
id 'org.springframework.boot' version '2.1.3.RELEASE'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
group = 'com'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.apis:google-api-services-youtube:v3-rev206-1.25.0'
implementation 'org.springframework.boot:spring-boot-starter'
implementation('org.apache.tomcat:tomcat-jdbc:9.0.10')
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation('org.mybatis:mybatis:3.4.6')
implementation('org.mybatis:mybatis-spring:1.3.2')
implementation('org.springframework.boot:spring-boot-starter-jdbc')
implementation('org.springframework.cloud:spring-cloud-starter-config')
compile group: 'org.postgresql', name: 'postgresql', version: '42.2.5'
runtimeOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
I really don't know what happen, I am pretty sure that these dependencies are the problem, but I have not figured out which one, i can not exclude any of them, because I am using them in project.
Never mind. I have fixed it. Indeed the problem was from my dependencies, my gradle.build was with problem. I have created a new project with spring initializer having all the dependencies and copied the new gradle.build from there and now is it working.
This is the new build.gradle from client
plugins {
id 'org.springframework.boot' version '2.1.3.RELEASE'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
group = 'com'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
}
ext {
set('springCloudVersion', 'Greenwich.RELEASE')
}
dependencies {
compile 'com.google.apis:google-api-services-youtube:v3-rev206-1.25.0'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.0.0'
implementation 'org.springframework.cloud:spring-cloud-starter-config'
runtimeOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'org.postgresql:postgresql'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}

Resources