Search code examples
springspring-bootspring-samlspring-cloud-config

SAMLBootstrap bean wipes out @Value injection from Cloud Config Server


When I run my app, metadataFile is always null when the bean below is created. I have a Spring Cloud Config Server which I see is hit before my breakpoint and the YML is successfully retrieved.

Even if the Config Server was down, the SPEL should provide a default. Has anyone run into @Value not evaluating and injecting values before their @Bean? I have many years using XML annotations, so perhaps I never have hit this with Annotation driven config, but it seems hard to believe I would not have run into this before. Very confused...

Within it:

 @Configuration
 public class Test {

  @Value("${someplace.saml.idp.metadata.file:'classpath:idp-metadata.xml'}")
  String metadataFile;

 @Bean
 MetadataProvider metadataProvider() {
        if(!StringUtils.isBlank(metadataFile) && metadataFile.startsWith("classpath:/")) {
            // do some stuff 
        } else {
            File metadatFile = new File(metadataFile);
        }
 }

UPDATE:

I shortened my example above for sake of brevity. The culprit wiping out the configuration values is this SAMLBootstrap bean. It seems to be required for annotation-configured Spring SAML2.

 @Bean
 SAMLBootstrap samlBootstrap() {
     return new SAMLBootstrap();
 }

Solution

  • UPDATE 2 (THE SOLUTION):

    The SAMLBootstrap bean needs to be declared with static. I found this in the last comment on another post: Spring Bean without id or name in Java Config