spring-projects / spring-projects/spring-security

WebTestUtilsTestRuntimeHints should work with reactive environment in tests with AOT enabled

Open
#12,598 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage type: bug
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

Describe the bug
Hi, im trying to get Sprint initializer generated project to work with AOT related tools. However it fails on test phase "processTestAot" with the following stacktrace:

Exception in thread "main" java.lang.NoClassDefFoundError: jakarta/servlet/Filter
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1012)
	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
	at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
	at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1012)
	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
	at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
	at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
	at org.springframework.security.test.aot.hint.WebTestUtilsTestRuntimeHints.registerFilterChainProxyHints(WebTestUtilsTestRuntimeHints.java:44)
	at org.springframework.security.test.aot.hint.WebTestUtilsTestRuntimeHints.registerHints(WebTestUtilsTestRuntimeHints.java:38)
	at org.springframework.test.context.aot.TestContextAotGenerator.lambda$processAheadOfTime$0(TestContextAotGenerator.java:145)

I believe this should work without "spring-boot-starter-web" aka MVC dependency as there is no non-servlet handling in WebTestUtilsTestRuntimeHints.java.

To Reproduce
Run tests via "build" or "aotTestClasses" task.

Expected behavior
Test should work successfully without MVC bloating.

Sample

A link to a GitHub repository with a minimal, reproducible sample.
Or https://start.spring.io/ with Spring Boot 3.0.2, Java 17, Kotlin language, Gradle .kts, Spring Reactive Web, GraalVM Native Support and Spring Security.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with WebTestUtilsTestRuntimeHints.java, especially registerHints and registerFilterChainProxyHints, then reproduce the failure using the reactive sample or by running the build or aotTestClasses task. Done means the test AOT phase succeeds for a reactive environment without requiring the MVC dependency or jakarta/servlet/Filter.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring, spring-boot
Domain
backend, security, testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.