Helder Sousa opened SPR-15968 and commented
Hi,
I'm not sure if this is similar to #18258 but when we have something like the following setup, the "env" is null when creating bean ServiceA
, but it is not null while creating ServiceB
.
Note that ServiceB
bean is being created before ServiceA
bean because of the @Import(ConfigB.class)
in ConfigA
@Configuration
@Import(ConfigB.class)
public class ConfigA {
@Autowired
Environment env;
@Bean
public static PropertySourcesPlaceholderConfigurer propertyPlaceHolderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
@Bean
public ServiceA serviceA() {
return new ServiceA(env.getProperty("myPropertyA"));
}
}
@Configuration
public class ConfigB {
@Autowired
Environment env;
@Bean
public ServiceB serviceB(ServiceA serviceA) {
return new ServiceB(serviceA, env.getProperty("myPropertyB"));
}
}
Everything works fine if the interface EnvironmentAware
is implemented by ConfigA
.
Is this a known limitation or should it work?
Affects: 4.3.10
Comment From: spring-projects-issues
Sergei Ustimenko commented
Seems like Environment
in ConfigA
should not be null
when ServiceA
gets created as propertyPlaceHolderConfigurer
declared to be static
.
Juergen Hoeller, could I investigate it little further and put an effort to fix it?
Comment From: bclozel
I can't reproduce this with Spring Framework 5.3.x.