Giter Club home page Giter Club logo

typesafeconfig-guice's People

Contributors

akozhemiakin avatar fayimora avatar mcrmfc avatar racc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

typesafeconfig-guice's Issues

Mechanism to instantiate annotation for use with Guice's Key class

For testing and for gradually retrofitting TypesafeConfig library into an existing codebase that has static or otherwise non-injectable config usages, it would be useful if there were an analog to Guice's built-in Names.named(String name) method to use in conjection with Guice's Key.get(Type type, Annotation annotation) method for querying the injector for specific named dependencies from the config.

Exception received when Lambda expressions used inside @Provides method.

Let's make a module:

public class TestModule extends AbstractModule {

@Override
    protected void configure() {

        Config config = ConfigFactory.load().getConfig("here.we.go");

        install(TypesafeConfigModule.fromConfigWithPackage(config, "stuff.package"));
    }
}

For some reason, we want to provide a String based on what's in the config (stupid example):

    @Provides
    @Singleton
    private String someString( @TypesafeConfig("one") String one,
                                   @TypesafeConfig("two") String two,
                                   @TypesafeConfig("three") String three) {

        return Optional.ofNullable(one)
            .map( s -> two)
            .orElse(three);
    }

This will result in the following exception:

Jun 23, 2017 1:48:01 PM com.google.inject.internal.MessageProcessor visit
INFO: An exception was caught and reported. Message: org.reflections.ReflectionsException: Can't resolve member named 0 for class package.for.TestModule.lambda$someString
org.reflections.ReflectionsException: Can't resolve member named 0 for class package.for.TestModule..lambda$someString

Apparently the Reflections package counts the lambdas in the method as separate classes (which they are).

This, however works:

    @Provides
    @Singleton
    private String someString( @TypesafeConfig("one") String one,
                                   @TypesafeConfig("two") String two,
                                   @TypesafeConfig("three") String three) {

         if(one == null) {
            return two;
        } else {
            return three;
        }
    }

Dependency on guice aop

I'm currently using finatra and it depends on guice:4.0 but this project depends on guice:4.0:no_aop. Both dependencies seem to have the same file names and path but different contents(I'm new to guice ๐Ÿ™ˆ)

The problem comes when I try to package a fatjar using something like sbt-assembly, it blows up because of the similar class names and paths.

/cc @racc

FastClasspathScanner is outdated -- consider porting to ClassGraph

Your project, racc/typesafeconfig-guice, depends on the outdated library FastClasspathScanner in the following source files:

FastClasspathScanner has been significantly reworked since the version your code depends upon:

  • a significant number of bugs have been fixed
  • some nontrivial API changes have been made to simplify and unify the API
  • FastClasspathScanner has been renamed to ClassGraph: https://github.com/classgraph/classgraph

ClassGraph is a significantly more robust library than FastClasspathScanner, and is more future-proof. All future development work will be focused on ClassGraph, and FastClasspathScanner will see no future development.

Please consider porting your code over to the new ClassGraph API, particularly if your project is in production or has downstream dependencies:

Feel free to close this bug report if this code is no longer in use. (You were sent this bug report because your project depends upon FastClasspathScanner, and has been starred by 52 users. Apologies if this bug report is not helpful.)

Guice error running application on generated jar

Hello Jason,

I'm using your library in my project and is working as expected but I have a little problem.
When I try to run my application as a stand-alone jar I'm getting this error.

Exception in thread "main" com.google.inject.CreationException: Unable to create injector, see the following errors:

1) No implementation for java.lang.Integer annotated with @com.github.racc.tscg.TypesafeConfig(value=server.instances) was bound.
  while locating java.lang.Integer annotated with @com.github.racc.tscg.TypesafeConfig(value=server.instances)
    for parameter 2 at com.myapp.infrastructure.conf.ServerConfig.<init>(ServerConfig.java:15)
  at com.myapp.infrastructure.CommonModule.configure(CommonModule.java:29)

2) No implementation for java.lang.Integer annotated with @com.github.racc.tscg.TypesafeConfig(value=server.port) was bound.
  while locating java.lang.Integer annotated with @com.github.racc.tscg.TypesafeConfig(value=server.port)
    for parameter 1 at com.myapp.infrastructure.conf.ServerConfig.<init>(ServerConfig.java:15)
  at com.myapp.infrastructure.CommonModule.configure(CommonModule.java:29)

3) No implementation for java.lang.String annotated with @com.github.racc.tscg.TypesafeConfig(value=amadeus.url) was bound.
  while locating java.lang.String annotated with @com.github.racc.tscg.TypesafeConfig(value=amadeus.url)
    for parameter 1 at com.myapp.infrastructure.conf.AmadeusConfig.<init>(AmadeusConfig.java:13)
  at com.myapp.infrastructure.CommonModule.configure(CommonModule.java:28)

4) No implementation for java.lang.String annotated with @com.github.racc.tscg.TypesafeConfig(value=amadeus.wsdl) was bound.
  while locating java.lang.String annotated with @com.github.racc.tscg.TypesafeConfig(value=amadeus.wsdl)
    for parameter 0 at com.myapp.infrastructure.conf.AmadeusConfig.<init>(AmadeusConfig.java:13)
  at com.myapp.infrastructure.CommonModule.configure(CommonModule.java:28)

5) No implementation for java.lang.String annotated with @com.github.racc.tscg.TypesafeConfig(value=server.host) was bound.
  while locating java.lang.String annotated with @com.github.racc.tscg.TypesafeConfig(value=server.host)
    for parameter 0 at com.myapp.infrastructure.conf.ServerConfig.<init>(ServerConfig.java:15)
  at com.myapp.infrastructure.CommonModule.configure(CommonModule.java:29)

6) No implementation for com.myapp.infrastructure.conf.hystrix.AbstractCommandConfig annotated with @com.github.racc.tscg.TypesafeConfig(value=hystrix.default.command) was bound.
  while locating com.myapp.infrastructure.conf.hystrix.AbstractCommandConfig annotated with @com.github.racc.tscg.TypesafeConfig(value=hystrix.default.command)
    for field at com.myapp.infrastructure.conf.hystrix.DefaultHystrixCommandConfig.commandConfig(DefaultHystrixCommandConfig.java:9)
  at com.myapp.infrastructure.CommonModule.configure(CommonModule.java:32)

7) No implementation for com.myapp.infrastructure.conf.hystrix.AbstractThreadPoolConfig annotated with @com.github.racc.tscg.TypesafeConfig(value=hystrix.default.threadPool) was bound.
  while locating com.myapp.infrastructure.conf.hystrix.AbstractThreadPoolConfig annotated with @com.github.racc.tscg.TypesafeConfig(value=hystrix.default.threadPool)
    for field at com.myapp.infrastructure.conf.hystrix.DefaultHystrixCommandConfig.threadPoolConfig(DefaultHystrixCommandConfig.java:9)
  at com.myapp.infrastructure.CommonModule.configure(CommonModule.java:32)

The extrange thing is that I have not problems when I run my application with gradle using gradle run command.
Here is one example of my configuration classes:

package com.copaair.connectmiles.infrastructure.conf;

import com.github.racc.tscg.TypesafeConfig;
import com.google.inject.Inject;

public class ServerConfig {

    private final String host;
    private final int port;
    private final int instances;

    @Inject
    public ServerConfig(@TypesafeConfig("server.host") String host,
                        @TypesafeConfig("server.port") int port,
                        @TypesafeConfig("server.instances") int instances) {
        this.host = host;
        this.port = port;
        this.instances = instances;
    }

    public String getHost() {
        return host;
    }

    public int getPort() {
        return port;
    }

    public int getInstances() {
        return instances;
    }
}

What am I missing?
Thank you very much!!!

Add ability to register additional extractors in extractor map

It would be convenient to be able to register additional extractors into the config module.

In particular, this would be nice for using this library in Scala projects, where often the consuming code can more naturally be expressed using a Scala type instead of the Java types injected by this library (e.g. scala.concurrent.duration.Duration instead of java.Time.Duration, a scala collection instead of java.util.List).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.