spring-cloud / spring-cloud-config

External configuration (server and client) for Spring Cloud
Apache License 2.0
1.95k stars 1.29k forks source link

VaultEnvironmentRepository doesn't load with embedded config server #1393

Closed scottfrederick closed 5 years ago

scottfrederick commented 5 years ago

When embedding config server in a Spring Boot application as described in the docs, and configuring a vault profile, the app will fail with an exception at startup:

2019-05-22 09:10:36.949 ERROR 79613 --- [           main] o.s.boot.SpringApplication               : Application run failed

java.lang.IllegalStateException: No HttpServletRequest available
    at org.springframework.cloud.config.server.environment.VaultEnvironmentRepository.findOne(VaultEnvironmentRepository.java:129) ~[spring-cloud-config-server-2.1.1.RELEASE.jar:2.1.1.RELEASE]
    at org.springframework.cloud.config.server.environment.CompositeEnvironmentRepository.findOne(CompositeEnvironmentRepository.java:61) ~[spring-cloud-config-server-2.1.1.RELEASE.jar:2.1.1.RELEASE]
    at org.springframework.cloud.config.server.environment.EnvironmentRepositoryPropertySourceLocator.locate(EnvironmentRepositoryPropertySourceLocator.java:55) ~[spring-cloud-config-server-2.1.1.RELEASE.jar:2.1.1.RELEASE]
    at org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.initialize(PropertySourceBootstrapConfiguration.java:97) ~[spring-cloud-context-2.1.1.RELEASE.jar:2.1.1.RELEASE]
    at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:649) ~[spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
    at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:373) ~[spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) ~[spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
    at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:139) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
    at org.springframework.boot.builder.SpringApplicationBuilder$run$0.call(Unknown Source) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]

This is apparently due to the fact that the VaultEnvironmentRepository requires an active HttpServletRequest so that it can extract the X-Config-State and X-Config-Token headers from the HTTP request sent to config server, and there is no HTTP request active when the app bootstraps configuration in the embedded mode.

ryanjbaxter commented 5 years ago

Fixed via f89724c

pankesh commented 5 years ago

i tried moving to 2.1.3.RELEASE to resolve the original issue but still can't get this working. The error I now get is

java.lang.IllegalStateException: No HttpServletRequest available
    at org.springframework.cloud.config.server.environment.HttpRequestConfigTokenProvider.getToken(HttpRequestConfigTokenProvider.java:41)
    at org.springframework.cloud.config.server.environment.VaultEnvironmentRepository.getToken(VaultEnvironmentRepository.java:218)
    at org.springframework.cloud.config.server.environment.VaultEnvironmentRepository.read(VaultEnvironmentRepository.java:209)
    at org.springframework.cloud.config.server.environment.VaultEnvironmentRepository.findOne(VaultEnvironmentRepository.java:147)
    at org.springframework.cloud.config.server.environment.CompositeEnvironmentRepository.findOne(CompositeEnvironmentRepository.java:61)
    at org.springframework.cloud.config.server.environment.EnvironmentRepositoryPropertySourceLocator.locate(EnvironmentRepositoryPropertySourceLocator.java:55)
    at org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.initialize(PropertySourceBootstrapConfiguration.java:97)
    at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:649)
    at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:373)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)

I am running in embedded mode (inside jHipster Registry). Here are other relevant piece of my code and configuration

Spring Boot App

@EnableEurekaServer
@EnableConfigServer
@SpringBootApplication
@EnableConfigurationProperties({ApplicationProperties.class, ConfigServerConfig.class})
@EnableDiscoveryClient
@EnableZuulProxy
public class JHipsterRegistryApp {
...
}

bootstrap.xml

  spring
      cloud:
        config:
            server:
                bootstrap: true
                composite:
                    - type: git
                      uri: https://...
                    - type: native
                      search-locations: file:///project/code/sample-projects/config
                    - type: vault
                      host: 192.168.99.100
                      port: 8200
                      uri: http://192.168.99.100:8200
                      scheme: http
                      kv-version: 2

Starting the application using java -jar target/jhipster-registry-5.0.2.jar --spring.profiles.active=composite

What am i missing?

ryanjbaxter commented 5 years ago

Please open a separate issue with a minimal project to reproduce the error