Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to implement overriding properties policy with rocoto ?
    text
    copied!<p>I would like to implement properties policy in my application : i want to define default properties inside my application, and in case of, i want to keep possibility to overriding this default parameters by a config file outside of the war file. </p> <p>So i define a ConfigModule.java:</p> <pre><code>public class ConfigModule extends AbstractModule { private static final Logger LOG = LoggerFactory.getLogger(BatchConfigModule.class); @Override protected void configure() { LOG.info("Start rocoto configuration"); Module rocotoModule = Rocoto.expandVariables(new ConfigurationModule() { @Override protected void bindConfigurations() { // default config LOG.debug("Default config"); bindProperties(Config.DEFAULT_CONFIG); LOG.debug("before config.properties"); // // For overriding default config File propertiesFile = new File(Resources.getResource("config.properties") .getFile()); if (propertiesFile.exists()) { LOG.info("config.properties was found in classpath: [" + propertiesFile.getAbsolutePath() + "]"); bindProperties(propertiesFile); } else { LOG.info("config.properties was not found in classpath"); } } }); install(rocotoModule); } } </code></pre> <p>Config.DEFAULT_CONFIG extends java.util.Properties and define default properties, each parameters in DEFAULT_CONFIG is like this => </p> <pre><code>DEFAULT_CONFIG.setProperty("testModeInt", "${testMode|false}"); </code></pre> <p>And i inject in my code property with @Named("testModeInt"). </p> <p>My problem is, if my config.properties is not present in classpath, i have an error : </p> <pre><code>Caused by: java.lang.IllegalStateException: Re-entry not allowed at com.google.inject.internal.util.$Preconditions.checkState(Preconditions.java:142) at org.nnsoft.guice.rocoto.configuration.ConfigurationModule.configure(ConfigurationModule.java:63) at com.google.inject.AbstractModule.configure(AbstractModule.java:59) at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:223) at com.google.inject.spi.Elements.getElements(Elements.java:101) at com.google.inject.spi.Elements.getElements(Elements.java:92) at com.google.inject.util.Modules$RealOverriddenModuleBuilder$1.configure(Modules.java:152) at com.google.inject.AbstractModule.configure(AbstractModule.java:59) at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:223) at com.google.inject.AbstractModule.install(AbstractModule.java:118) at net.antoine.ConfigModule.configure(ConfigModule.java:51) </code></pre> <p>Which i just don't understand, where is this problem come from, or maybe this implementation is not good, another idea ? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload