Skip to content

Commit 0dba729

Browse files
committed
Polish "Allow MethodReference to support a more flexible signature"
See gh-29005
1 parent bbe5e91 commit 0dba729

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

spring-context/src/main/java/org/springframework/context/aot/ApplicationContextInitializationCodeGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private CodeBlock apply(ClassName className) {
139139
}
140140
else if (name.equals(ConfigurableEnvironment.class.getName())
141141
|| name.equals(Environment.class.getName())) {
142-
return CodeBlock.of("$L.getConfigurableEnvironment()", APPLICATION_CONTEXT_VARIABLE);
142+
return CodeBlock.of("$L.getEnvironment()", APPLICATION_CONTEXT_VARIABLE);
143143
}
144144
else if (name.equals(ResourceLoader.class.getName())) {
145145
return CodeBlock.of(APPLICATION_CONTEXT_VARIABLE);

spring-context/src/test/java/org/springframework/context/aot/ApplicationContextAotGeneratorTests.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@
6161
import org.springframework.context.testfixture.context.generator.annotation.LazyAutowiredMethodComponent;
6262
import org.springframework.context.testfixture.context.generator.annotation.LazyConstructorArgumentComponent;
6363
import org.springframework.context.testfixture.context.generator.annotation.LazyFactoryMethodArgumentComponent;
64+
import org.springframework.context.testfixture.context.generator.annotation.PropertySourceConfiguration;
65+
import org.springframework.core.env.ConfigurableEnvironment;
6466
import org.springframework.core.env.Environment;
67+
import org.springframework.core.env.PropertySource;
6568
import org.springframework.core.io.ResourceLoader;
6669

6770
import static org.assertj.core.api.Assertions.assertThat;
@@ -279,6 +282,19 @@ void processAheadOfTimeWhenHasCglibProxyWriteProxyAndGenerateReflectionHints() t
279282
.withMemberCategory(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)).accepts(context.getRuntimeHints());
280283
}
281284

285+
@Test
286+
void processAheadOfTimeWithPropertySource() {
287+
GenericApplicationContext applicationContext = new AnnotationConfigApplicationContext();
288+
applicationContext.registerBean(PropertySourceConfiguration.class);
289+
testCompiledResult(applicationContext, (initializer, compiled) -> {
290+
GenericApplicationContext freshApplicationContext = toFreshApplicationContext(initializer);
291+
ConfigurableEnvironment environment = freshApplicationContext.getEnvironment();
292+
PropertySource<?> propertySource = environment.getPropertySources().get("testp1");
293+
assertThat(propertySource).isNotNull();
294+
assertThat(propertySource.getProperty("from.p1")).isEqualTo("p1Value");
295+
});
296+
}
297+
282298
private Consumer<List<? extends JdkProxyHint>> doesNotHaveProxyFor(Class<?> target) {
283299
return hints -> assertThat(hints).noneMatch(hint -> hint.getProxiedInterfaces().get(0).equals(target));
284300
}

spring-context/src/test/java/org/springframework/context/aot/ApplicationContextInitializationCodeGeneratorTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void argumentForUnsupportedEnvironmentIsNotResolved() {
6565

6666
static Stream<Arguments> methodArguments() {
6767
String applicationContext = "applicationContext";
68-
String environment = applicationContext + ".getConfigurableEnvironment()";
68+
String environment = applicationContext + ".getEnvironment()";
6969
return Stream.of(
7070
Arguments.of(DefaultListableBeanFactory.class, "beanFactory"),
7171
Arguments.of(ConfigurableListableBeanFactory.class, "beanFactory"),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2002-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.context.testfixture.context.generator.annotation;
18+
19+
import org.springframework.context.annotation.Configuration;
20+
import org.springframework.context.annotation.PropertySource;
21+
22+
@Configuration(proxyBeanMethods = false)
23+
@PropertySource(name = "testp1", value = "classpath:org/springframework/context/annotation/p1.properties")
24+
public class PropertySourceConfiguration {
25+
26+
}

0 commit comments

Comments
 (0)