- 
                Notifications
    You must be signed in to change notification settings 
- Fork 38.8k
Description
Keith Donald opened SPR-7975 and commented
I'm unable to inject environment properties or ApplicationContext services such as ResourceLoader into @FeatureConfiguration classes.  This appears possible with @Configuration classes but not @FeatureConfiguration classes.
An example of a @FeatureConfiguration that fails:
@FeatureConfiguration
public class MvcFeatureConfig {
	
    @Inject
    private ResourceLoader resourceLoader;
	
    @Feature
    public MvcAnnotationDriven annotatedControllers(Validator validator,
        @Value("#{environment['facebook.appId']}") String facebookAppId,
        @Value("#{environment['facebook.appSecret']}") String facebookAppSecret) {
        
        return new MvcAnnotationDriven().validator(validator).
            argumentResolvers(new DeviceWebArgumentResolver(),
            new FacebookWebArgumentResolver(facebookAppId, facebookAppSecret),
            new AccountWebArgumentResolver(),
            new DateTimeZoneWebArgumentResolver(),
            new LocationWebArgumentResolver());
    }
	
    @Feature
    public MvcResources resourceHandler() {
        return new MvcResources("/resources/**", resourceLoader.getResource("/resources/"));
    }
}
This will first fail because Spring tries to subclass the String environment @Values facebookAppId and facebookAppSecret, instead of injecting them.  Changing those to member fields doesn't work either, as no injection gets performed on the @Value fields.  The ResourceLoader field also remains null, resulting in a NullPointerException when resourceHandler() is invoked.
Affects: 3.1 M1
Attachments:
- mylyn-context.zip (948 bytes)
Issue Links:
- Process @ImportResource with current ResourceLoader [SPR-7973] #12628 Process @ImportResourcewith current ResourceLoader
- @Feature methods do not accept @Value-annotated parameters [SPR-7974] #12629 @Featuremethods do not accept@Value-annotatedparameters
Referenced from: commits 704b229, 5cfbed8
1 votes, 2 watchers