I'd like to add Jasypt to the configuration. So I would like to create a plugin that decrypts the application.conf entries that are needed.

I've created a simple plugin, but the db configuration has already been read/executed by the time my onStart() is called.

I've tried GlobalSettings onLoadConfig and beforeStart, both come after the db is configured.

Where can I hook in to achieve my goal?

有帮助吗?

解决方案

public class Global extends GlobalSettings {

// inject Jasypt StandardPBEStringEncryptor

@Override
public Configuration onLoadConfig(Configuration configuration, File file, ClassLoader classLoader) {
    final Config config = ConfigFactory.parseString(String.format("db.default.user=%s", callJasyptStringEncryptor()));

    return new Configuration(config.withFallback(configuration.getWrappedConfiguration().underlying()));
}}

其他提示

If you are using scala,

override def onLoadConfig(config: Configuration, path: File, classloader: ClassLoader, mode: Mode.Mode): Configuration = {
        val parsed = ConfigFactory.parseString("db.default.user=\"JasyptText\"")
        new Configuration(parsed.withFallback(config.underlying))
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top