Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@Scheduled method in test class not supported anymore #33286

Closed
romainmoreau opened this issue Jul 28, 2024 · 0 comments
Closed

@Scheduled method in test class not supported anymore #33286

romainmoreau opened this issue Jul 28, 2024 · 0 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression
Milestone

Comments

@romainmoreau
Copy link

Affects: 6.1.9+


Since Spring 6.1.9 (and I believe since #33009), it's not possible to declare a @Scheduled method directly in a test class because the following exception is thrown when the test is run:

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'com.example.demo.DemoApplicationTestsWithoutBoot.ORIGINAL' available
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:923)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1361)
        at org.springframework.beans.factory.support.AbstractBeanFactory.isSingleton(AbstractBeanFactory.java:459)
        at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.postProcessAfterInitialization(ScheduledAnnotationBeanPostProcessor.java:311)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:439)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1805)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:413)
        at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:144)
        at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:98)
        at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:260)
        at org.springframework.test.context.junit.jupiter.SpringExtension.postProcessTestInstance(SpringExtension.java:160)
        at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212)
        at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:194)
        at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709)
        at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556)
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546)
        at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(StreamSpliterators.java:310)
        at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:735)
        at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:734)
        at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:782)
        at java.base/java.util.Optional.orElseGet(Optional.java:364)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1597)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1597)

It's not blocking because as a workaround one can refactore the test by moving the @Scheduled method into a new @Component for example but it's still a regression.

Demo: https://github.com/romainmoreau/scheduled-in-test-regression

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jul 28, 2024
@jhoeller jhoeller added type: regression A bug that is also a regression in: core Issues in core modules (aop, beans, core, context, expression) and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jul 28, 2024
@jhoeller jhoeller self-assigned this Jul 28, 2024
@jhoeller jhoeller added this to the 6.1.12 milestone Jul 28, 2024
thred added a commit to porscheinformatik/pnet-idp-client that referenced this issue Jul 29, 2024
Updated to Spring Boot 3.3.2 in order to reproduce a bug.
The problem is caused by directly instantiating the
DefaultSaml2CredentialsManager that contains annotated
methods and post processing the instantiated manager.

Currently, it is not possible to instantiate the manager
in this fashion and the postProcess call was removed.
As a result, it is now necessary to pass a bean as
Saml2CredentialsManager.

It seems to be caused by the same change, that led to
spring-projects/spring-framework#33286
and was fixed just hours ago.

It's a breaking change! The two credential methods in the
PartnerNetSaml2Configurer are package-private now.
Replace the call by simply passing a
DefaultSaml2CredentialsManager bean initialized with
the configSupplier instead of using the credentials
methods with the configSupplier.

The methods will be restored with the Upgrade to 3.3.3,
if the change in Spring Boot is fixing for our error,
too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

3 participants