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]
...
UserServiceshould be used in the test?UserServiceis a Spring@Serviceand the problem is contained in the code. Using a profileintegrationtest(or messing around with@EnableScheduling) does not solve the problem. See my simple solution below.