You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
gradlew nativeTest fails with Failed to instantiate [org.springframework.security.test.context.support.WithUserDetailsSecurityContextFactory]: No default constructor found
#12614
Describe the bug
Spring Boot 3.0.2 + web + security + graalvm 22.3.0
Test with annotation @WithUserDetails fails with exception when run ./gradlew nativeTest, but is OK in JVM test run
JUnit Jupiter:IndexControllerTest:getStatus()
MethodSource [className = 'com.example.nativesecurity.IndexControllerTest', methodName = 'getStatus', methodParameterTypes = '']
=> java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.test.context.support.WithUserDetailsSecurityContextFactory': Failed to instantiate [org.springframework.security.test.context.support.WithUserDetailsSecurityContextFactory]: No default constructor found
org.springframework.security.test.context.support.WithSecurityContextTestExecutionListener.createFactory(WithSecurityContextTestExecutionListener.java:176)
org.springframework.security.test.context.support.WithSecurityContextTestExecutionListener.createTestSecurityContext(WithSecurityContextTestExecutionListener.java:134)
org.springframework.security.test.context.support.WithSecurityContextTestExecutionListener.createTestSecurityContext(WithSecurityContextTestExecutionListener.java:113)
org.springframework.security.test.context.support.WithSecurityContextTestExecutionListener.beforeTestMethod(WithSecurityContextTestExecutionListener.java:81)
org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:288)
[...]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.test.context.support.WithUserDetailsSecurityContextFactory': Failed to instantiate [org.springframework.security.test.context.support.WithUserDetailsSecurityContextFactory]: No default constructor found
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1306)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1198)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:561)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:521)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:321)
[...]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.test.context.support.WithUserDetailsSecurityContextFactory]: No default constructor found
org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:83)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1300)
[...]
Caused by: java.lang.NoSuchMethodException: org.springframework.security.test.context.support.WithUserDetailsSecurityContextFactory.<init>()
[email protected]/java.lang.Class.getConstructor0(DynamicHub.java:3585)
[email protected]/java.lang.Class.getDeclaredConstructor(DynamicHub.java:2754)
org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:79)
[...]
I tried to add reflect-config.json with following content and this not helped:
It is indeed a bug and it has been fixed in spring-projects/spring-framework#29855, which will be available in Spring Framework 6.0.5, scheduled for Feb 15th, and Spring Security 6.0.2 scheduled for Feb 20th.
You can change the Spring Framework version to 6.0.5-SNAPSHOT to test the fix. I already did that using your sample and the test passes.
Describe the bug
Spring Boot 3.0.2 + web + security + graalvm 22.3.0
Test with annotation @WithUserDetails fails with exception when run ./gradlew nativeTest, but is OK in JVM test run
I tried to add reflect-config.json with following content and this not helped:
To Reproduce
Checkout sample and ./gradlew nativeTest
Expected behavior
Test should run fine
Sample
https://github.com/naihil/native-security
Maybe there is some other workarounds?
The text was updated successfully, but these errors were encountered: