0

I'm on Spring Boot 3.5.6 with Java 25 (Temurin). I followed this tutorial.

My config:

@Configuration
@EnableScheduling
@Profile(value = "!integrationtest")
public class SchedulingConfig
{
}

My test class:

@SpringBootTest(classes = {AppConfig.class, SchedulingConfig.class})
@ActiveProfiles(value = {"integrationtest"})
class UserServiceIT
{
    @Autowired
    private UserService userService;
...

The @Autowired cannot be resolved (it worked before implementing the above code):

...
2025-10-22T11:22:55.004+02:00  INFO 24444 --- [           main] m.s.m.service.UserServiceIT              : Started UserServiceIT in 0.767 seconds (process running for 2.076)
2025-10-22T11:22:55.427+02:00  WARN 24444 --- [           main] o.s.test.context.TestContextManager      : Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener] to prepare test instance [mycompany.myproject.service.UserServiceIT@5b12012e]

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mycompany.myproject.service.UserServiceIT': Unsatisfied dependency expressed through field 'userService': No qualifying bean of type 'mycompany.myproject.service.UserService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:788) ~[spring-beans-6.2.11.jar:6.2.11]
...
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'mycompany.myproject.service.UserService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:2303) ~[spring-beans-6.2.11.jar:6.2.11]
...
3
  • What implementation of UserService should be used in the test? Commented Oct 22 at 11:06
  • And where do you have the problem from your question title? "cannot deactivate...": To me it doesn't look as if you were deactivating anything anywhere... Commented Oct 22 at 11:14
  • UserService is a Spring @Service and the problem is contained in the code. Using a profile integrationtest (or messing around with @EnableScheduling) does not solve the problem. See my simple solution below. Commented Oct 22 at 12:35

1 Answer 1

0

Simple Solution found

@SpringBootTest(properties = "scheduling.enabled=false")

in the Integration test class and

@ConditionalOnProperty(
    name = "scheduling.enabled",
    havingValue = "true",
    matchIfMissing = true  // default: scheduling is active
)

in the class containing @Scheduled methods.

@EnableScheduling is not affected by this and does not affect this, I moved the annotation back to AppConfig and removed SchedulingConfig.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.