diff --git a/spring-test/src/main/java/org/springframework/test/context/support/DependencyInjectionTestExecutionListener.java b/spring-test/src/main/java/org/springframework/test/context/support/DependencyInjectionTestExecutionListener.java index ca6648346edf..2e24f435c63d 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/DependencyInjectionTestExecutionListener.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/DependencyInjectionTestExecutionListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ import org.springframework.beans.factory.config.AutowireCapableBeanFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.CommonAnnotationBeanPostProcessor; import org.springframework.context.support.GenericApplicationContext; import org.springframework.core.Conventions; import org.springframework.test.context.TestContext; @@ -153,10 +154,14 @@ private void injectDependenciesInAotMode(TestContext testContext) throws Excepti Object bean = testContext.getTestInstance(); Class clazz = testContext.getTestClass(); + ConfigurableListableBeanFactory beanFactory = gac.getBeanFactory(); - AutowiredAnnotationBeanPostProcessor beanPostProcessor = new AutowiredAnnotationBeanPostProcessor(); - beanPostProcessor.setBeanFactory(beanFactory); - beanPostProcessor.processInjection(bean); + AutowiredAnnotationBeanPostProcessor autowiredAnnotationBpp = new AutowiredAnnotationBeanPostProcessor(); + autowiredAnnotationBpp.setBeanFactory(beanFactory); + autowiredAnnotationBpp.processInjection(bean); + CommonAnnotationBeanPostProcessor commonAnnotationBpp = new CommonAnnotationBeanPostProcessor(); + commonAnnotationBpp.setBeanFactory(beanFactory); + commonAnnotationBpp.processInjection(bean); beanFactory.initializeBean(bean, clazz.getName() + AutowireCapableBeanFactory.ORIGINAL_INSTANCE_SUFFIX); testContext.removeAttribute(REINJECT_DEPENDENCIES_ATTRIBUTE); } diff --git a/spring-test/src/test/java/org/springframework/test/context/aot/samples/basic/BasicSpringJupiterTests.java b/spring-test/src/test/java/org/springframework/test/context/aot/samples/basic/BasicSpringJupiterTests.java index 038350e5ed1e..42354467d7b4 100644 --- a/spring-test/src/test/java/org/springframework/test/context/aot/samples/basic/BasicSpringJupiterTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/aot/samples/basic/BasicSpringJupiterTests.java @@ -16,6 +16,7 @@ package org.springframework.test.context.aot.samples.basic; +import jakarta.annotation.Resource; import org.junit.jupiter.api.Nested; import org.springframework.beans.factory.annotation.Autowired; @@ -57,11 +58,15 @@ }) public class BasicSpringJupiterTests { + @Resource + Integer magicNumber; + @org.junit.jupiter.api.Test void test(@Autowired ApplicationContext context, @Autowired MessageService messageService, @Value("${test.engine}") String testEngine) { assertThat(messageService.generateMessage()).isEqualTo("Hello, AOT!"); assertThat(testEngine).isEqualTo("jupiter"); + assertThat(magicNumber).isEqualTo(42); assertEnvProperties(context); } diff --git a/spring-test/src/test/java/org/springframework/test/context/aot/samples/basic/BasicTestConfiguration.java b/spring-test/src/test/java/org/springframework/test/context/aot/samples/basic/BasicTestConfiguration.java index 33f95821d6e5..06d25d1edece 100644 --- a/spring-test/src/test/java/org/springframework/test/context/aot/samples/basic/BasicTestConfiguration.java +++ b/spring-test/src/test/java/org/springframework/test/context/aot/samples/basic/BasicTestConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,4 +45,9 @@ MessageService spanishMessageService() { return new SpanishMessageService(); } + @Bean + Number magicNumber() { + return 42; + } + }