We have a Spring boot v 2.7.x application, running on java 11. And we want to switch to java 17 and Spring boot 3.0.0. But now, when I am making the changes locally (IDE is IntelliJ), the following test class:
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import static org.junit.jupiter.api.Assertions.assertTrue;
@SpringBootTest
class MyCompanyAppRegistrationApplicationTests {
@Test
void contextLoads() {
assertTrue(true);
}
}
started failing with this error:
java.lang.IllegalStateException: Failed to load ApplicationContext for [WebMergedContextConfiguration@55a66bbf
testClass = company.registration.MyCompanyAppRegistrationApplicationTests,
locations = [],
classes = [company.registration.MyCompanyAppRegistrationApplication],
contextInitializerClasses = [], activeProfiles = [], propertySourceLocations = [],
propertySourceProperties = ["org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true"],
contextCustomizers = [org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@1e6cc850,
org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@48b22fd4,
org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0,
org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@178270b2,
org.springframework.boot.test.autoconfigure.actuate.observability.ObservabilityContextCustomizerFactory$DisableObservabilityContextCustomizer@9da1,
org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0,
org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@3d36dff4,
org.springframework.boot.test.context.SpringBootTestAnnotation@3954286c],
resourceBasePath = "src/main/webapp", contextLoader = org.springframework.boot.test.context.SpringBootContextLoader, parent = null]
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [company.registration.MyCompanyAppRegistrationApplication]: Failed to load class [javax.servlet.Filter]
Caused by: java.io.IOException: Failed to load class [javax.servlet.Filter]
Caused by: java.lang.ClassNotFoundException: javax.servlet.Filter
Since Spring 3.x supports JakartaEE 9 and 10, I have changed all the needed packages from javax* to Jakarta.*. But obviously for some reason somewhere Javax.servlet.Filter is wanted. Where I should look into this? Should I look at the dependencies in the pom file? The pom file looks like this:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<java.version>17</java.version>
<commons-lib.version>3.2.1</commons-lib.version>
<datasource-lib.version>1.4.0</datasource-lib.version>
<wiremock.version>2.27.2</wiremock.version>
<archunit.version>1.0.1</archunit.version>
<guava.version>31.1-jre</guava.version>
<h2.version>1.4.200</h2.version>
<jakarta.validaton.api.version>3.0.0</jakarta.validaton.api.version>
</properties>
<dependencies>
<!-- internal dependencies-->
<dependency>
<groupId>my company</groupId>
<artifactId>commons-lib</artifactId>
<version>${commons-lib.version}</version>
</dependency>
<dependency>
<groupId>my company</groupId>
<artifactId>datasource-lib</artifactId>
<version>${datasource-lib.version}</version>
</dependency>
<!--PROVIDED-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>${jakarta.validaton.api.version}</version>
</dependency>
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<version>3.1.0</version>
</dependency>
<!--TEST-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<version>${wiremock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit</artifactId>
<version>${archunit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.8.0.2131</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.8</version>
<configuration>
<rules>
</rules>
</configuration>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>central</id>
<name>libs-staging-local</name>
<url>https://some-url</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>libs-snapshot-local</name>
<url>https://some-url</url>
</snapshotRepository>
</distributionManagement>
<repositories>
<repository>
<id>azd-releases</id>
<url>https://some-url</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>azd-snapshots</id>
<url>https://some-url</url>
<releases>
<enabled>false</enabled>
</releases>
</repository>
<repository>
<id>apache-central</id>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
</repositories>
mvn dependency:tree