Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A way to disable default PropertiesConfigReader #534

Open
wants to merge 4 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@
import java.util.Properties;

import com.google.inject.AbstractModule;
import com.google.inject.Scopes;
import com.google.inject.binder.LinkedBindingBuilder;
import com.google.inject.multibindings.Multibinder;
import com.google.inject.name.Names;
import com.netflix.archaius.api.CascadeStrategy;
import com.netflix.archaius.api.Config;
import com.netflix.archaius.api.ConfigReader;
import com.netflix.archaius.api.inject.DefaultLayer;
import com.netflix.archaius.api.inject.RemoteLayer;
import com.netflix.archaius.config.MapConfig;
import com.netflix.archaius.readers.PropertiesConfigReader;

/**
* Guice Module for enabling archaius and making its components injectable. Installing this
Expand Down Expand Up @@ -239,8 +242,33 @@ protected void bindApplicationConfigurationOverrideResource(String overrideResou
Multibinder.newSetBinder(binder(), String.class, ApplicationOverrideResources.class).permitDuplicates().addBinding().toInstance(overrideResource);
}

/**
* Binding ConfigReaders has been removed from InternalArchaiusModule class which is locked for modification and it has been added to configure as overridable method.
* <br /><br />
* <b>For example to disable default PropertyConfigReader and add TypesafeConfigReader</b>
* <br />
* <code>
* <pre>
* install(new ArchaiusModule() {
* {@literal @}Override
* protected void bindDefaultReaders() {}
*
* {@literal @}Override
* protected void configureArchaius() {
* Multibinder.newSetBinder(this.binder(), ConfigReader.class).addBinding().to(TypesafeConfigReader.class).asEagerSingleton();
* }
* });
* </pre>
* </code>
*/
protected void bindDefaultReaders() {
Multibinder.newSetBinder(binder(), ConfigReader.class)
.addBinding().to(PropertiesConfigReader.class).in(Scopes.SINGLETON);
}

@Override
protected final void configure() {
bindDefaultReaders();
install(new InternalArchaiusModule());

configureArchaius();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,13 @@
import com.google.inject.AbstractModule;
import com.google.inject.Inject;
import com.google.inject.Provides;
import com.google.inject.Scopes;
import com.google.inject.Singleton;
import com.google.inject.matcher.Matchers;
import com.google.inject.multibindings.Multibinder;
import com.netflix.archaius.ConfigProxyFactory;
import com.netflix.archaius.DefaultConfigLoader;
import com.netflix.archaius.DefaultDecoder;
import com.netflix.archaius.DefaultPropertyFactory;
import com.netflix.archaius.api.CascadeStrategy;
import com.netflix.archaius.api.Config;
import com.netflix.archaius.api.ConfigLoader;
import com.netflix.archaius.api.ConfigReader;
import com.netflix.archaius.api.Decoder;
import com.netflix.archaius.api.PropertyFactory;
import com.netflix.archaius.api.PropertyRepository;
import com.netflix.archaius.api.*;
import com.netflix.archaius.api.config.CompositeConfig;
import com.netflix.archaius.api.config.SettableConfig;
import com.netflix.archaius.api.exceptions.ConfigException;
Expand All @@ -31,13 +23,11 @@
import com.netflix.archaius.config.EnvironmentConfig;
import com.netflix.archaius.config.SystemConfig;
import com.netflix.archaius.interpolate.ConfigStrLookup;
import com.netflix.archaius.readers.PropertiesConfigReader;

import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;

import javax.inject.Named;
import javax.inject.Provider;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;

final class InternalArchaiusModule extends AbstractModule {
static final String CONFIG_NAME_KEY = "archaius.config.name";
Expand Down Expand Up @@ -65,9 +55,6 @@ protected void configure() {
bind(ConfigurationInjectingListener.class).toInstance(listener);
requestStaticInjection(ConfigurationInjectingListener.class);
bindListener(Matchers.any(), listener);

Multibinder.newSetBinder(binder(), ConfigReader.class)
.addBinding().to(PropertiesConfigReader.class).in(Scopes.SINGLETON);
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
package com.netflix.archaius.guice;

import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.multibindings.Multibinder;
import com.netflix.archaius.api.ConfigReader;
import com.netflix.archaius.readers.PropertiesConfigReader;
import org.junit.Test;

public class InternalArchaiusModuleTest {

@Test
public void succeedOnDuplicateInstall() {
Guice.createInjector(
new InternalArchaiusModule(),
new InternalArchaiusModule());
new AbstractModule() {
@Override
protected void configure() {
Multibinder.newSetBinder(this.binder(), ConfigReader.class).addBinding().to(PropertiesConfigReader.class).asEagerSingleton();
}
},
new InternalArchaiusModule(),
new InternalArchaiusModule()
);
}
}