Blokje5
Blokje5

Reputation: 5023

Passing a list to an environment variable to exclude certain classes from auto configuration

In Spring you can exclude certain classes from autoconfiguration by defining them in the spring.autoconfigure.exclude property. In my case, we are using yaml to define to exclude certain classes:

spring:
  autoconfigure:
    exclude: |
      org.springframework.boot.actuate.autoconfigure.MetricFilterAutoConfiguration,
      org.springframework.boot.actuate.autoconfigure.MetricRepositoryAutoConfiguration,
      org.springframework.boot.actuate.autoconfigure.MetricsDropwizardAutoConfiguration,
      org.springframework.boot.actuate.autoconfigure.MetricsChannelAutoConfiguration,
      org.springframework.boot.actuate.autoconfigure.MetricExportAutoConfiguration,
      org.springframework.boot.actuate.autoconfigure.PublicMetricsAutoConfiguration

to exclude the actuator setup. However, as that only needs to happen in certain environments, I want to externalize this setup and pass it as an environment variable. Spring allows you to pass configuration as an environment variable of the form SPRING_AUTOCONFIGURE_EXCLUDE, but how would I pass the list in this case? I could not find anything in Springs documentation on externalized configuration that gave me the answer.

Upvotes: 1

Views: 571

Answers (1)

Marko Previsic
Marko Previsic

Reputation: 1960

You can do it as follows:

export SPRING_AUTOCONFIGURE_EXCLUDE=org.springframework.boot.actuate.autoconfigure.MetricFilterAutoConfiguration,org.springframework.boot.actuate.autoconfigure.MetricRepositoryAutoConfiguration,org.springframework.boot.actuate.autoconfigure.MetricsDropwizardAutoConfiguration,org.springframework.boot.actuate.autoconfigure.MetricsChannelAutoConfiguration,org.springframework.boot.actuate.autoconfigure.MetricExportAutoConfiguration,org.springframework.boot.actuate.autoconfigure.PublicMetricsAutoConfiguration

Upvotes: 1

Related Questions