Skip to content
This repository has been archived by the owner on Dec 12, 2018. It is now read-only.

Overriding Default Configuration

Les Hazlewood edited this page Apr 25, 2016 · 7 revisions

For the core SDK only (not any of the integrations), we have this spec.

However, this spec doesn't account for things like .properties which is more idiomatic for Java applications than YAML. Because of this, our loading order needs to be based on that spec as well the locations we already have defined for the Servlet Spec.

The loading order should be as follows.

Core SDK Only

For the Core SDK only when the servlet integration is not used. Values found in later locations override values found in earlier locations:

  1. classpath:com/stormpath/sdk/config/stormpath.properties This contains the default configuration as defined here (but with everything still prefixed with 'stormpath.'). Note that this can be a .properties file if it makes our lives easier since it won't be referenced by users directly.
  2. classpath:stormpath.properties
  3. classpath:stormpath.json
  4. classpath:stormpath.yaml
  5. $HOME/.stormpath/apiKey.properties
  6. $HOME/.stormpath/stormpath.properties
  7. $HOME/.stormpath/stormpath.json
  8. $HOME/.stormpath/stormpath.yaml
  9. System.getProperty("user.dir") + File.separator + "apiKey.properties"
  10. System.getProperty("user.dir") + File.separator + "stormpath.properties
  11. System.getProperty("user.dir") + File.separator + "stormpath.json"
  12. System.getProperty("user.dir") + File.separator + "stormpath.yaml"
  13. Environment Variables (with dot notation converted to uppercase + underscore convention as described here.
  14. JVM System Properties

If 2, 5 or 8 is found to exist and Jackson is not on the classpath, log a warn message that clarifies that they need to add Jackson to the classpath. If 3, 6, or 9 is found to exist and SnakeYaml is not on the classpath, log a warn message that clarifies that they need to add SnakeYaml to the classpath. If no .json or .yaml files are found, Jackson and Snake do not need to be on the classpath and everything should still 'just work'.

I suspect they very large majority of people won't care about the two dependencies. And if they do, they can <exclude> them from their Maven/Gradle config. We should have some documentation on this in our guides though so they can know that they can proactively exclude these dependencies if they want (with the caveat that we'll log a warn message if we find a respective config file).

Servlet Integration

When the servlet integration is used (but not Spring or Spring Boot). Values found in later locations override values found in earlier locations:

  1. classpath:com/stormpath/sdk/config/stormpath.properties
  2. classpath:com/stormpath/sdk/servlet/config/web.stormpath.properties This reflects additional web-specific default configuration. Again, this can be a .properties file if it makes our lives easier since it won't be referenced by users directly.
  3. classpath:stormpath.properties
  4. classpath:stormpath.json
  5. classpath:stormpath.yml
  6. /WEB-INF/stormpath.properties
  7. /WEB-INF/stormpath.json
  8. /WEB-INF/stormpath.yml
  9. Servlet Context Parameters
  10. $HOME/.stormpath/apiKey.properties
  11. $HOME/.stormpath/stormpath.properties
  12. $HOME/.stormpath/stormpath.json
  13. $HOME/.stormpath/stormpath.yml
  14. System.getProperty("user.dir") + File.separator + "apiKey.properties"
  15. System.getProperty("user.dir") + File.separator + "stormpath.properties"
  16. System.getProperty("user.dir") + File.separator + "stormpath.json"
  17. System.getProperty("user.dir") + File.separator + "stormpath.yml"
  18. Environment Variables (with dot notation converted to uppercase + underscore convention as described here.
  19. JVM System Properties

Same comments about Jackson/Snake being in the classpath.

Spring Boot

None of the above applies except for $HOME/.stormpath/apiKey.properties, which our Spring Boot integration supports today. In Spring Boot, we let Spring Boot define the config override locations and order, and users can use that.

Standard Spring

Spring-only (non Boot) users can define PropertyPlaceholderConfigurers or @PropertySource themselves. For those that want to configure their application with YAML, they can use YamlPropertiesFactoryBean.