Skip to content

Configuration

Fabrice Daugan edited this page Apr 13, 2018 · 1 revision

Code summary

@Autowired
private ConfigurationResource configuration;
...
configuration.get("my-key");

See ConfigurationResource.java

Description

Configuration can be retrieved:

  • From built-in Spring variable resolution: static, and resolved only when the context is started
@Value("$(my-key:default-value"}
private String value;
  • From ConfigurationResource, a persistent database backed and cached configuration
@Autowired
private ConfigurationResource configuration;
...
configuration.get("my-key", "default-value");
configuration.get("my-key", 42);
configuration.get("my-key");

Failover

Built-in Spring property resolver use the System.getProperty then application.properties, then the default value.

For ConfigurationResource, the sequence is the same with database lookup first.

Encryption

Both solutions are backed by Jasypt to protect secret from configuration files and stored sensitive data in database. It is possible to benefit the same security level for other stored data:

@Autowired
private CryptoHelper cryptoHelper;
...
cryptoHelper.encryptAsNeeded(value)
cryptoHelper.encrypt(value)
cryptoHelper.decryptAsNeeded(value)
cryptoHelper.decrypt(value)
Clone this wiki locally