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

'@Configuration' is not applicable to parameter #290

Open
costimuraru opened this issue Apr 7, 2016 · 2 comments
Open

'@Configuration' is not applicable to parameter #290

costimuraru opened this issue Apr 7, 2016 · 2 comments

Comments

@costimuraru
Copy link

Hey

I'm trying to inject a config param, as shown in the example below, but I'm receiving the following error: '@Configuration' is not applicable to parameter.

public class AppConfig {

    private String numberOfThings;

    @Inject
    public AppConfig(@Configuration("configs.qty.things") String numberOfThings) {
        this.numberOfThings = numberOfThings;
    }
}

I'm basically trying to obtain the same behavior as with the @Named("someValue") annonation in Guice.

Looking at the @Configuration annonation target I can see only ElementType.FIELD and ElementType.METHOD. No ElementType.PARAMETER is specified. Am I doing something wrong?

@elandau
Copy link
Contributor

elandau commented Apr 12, 2016

'@configuration' cannot work on constructor arguments as Guice does not support custom injections like this. Try this instead

public class AppConfig {
   @Configuration("config.qty.things")
    private String numberOfThings;
}

@Loki-Afro
Copy link

@elandau and if @Configuration "extends" @Named? I am by far no guice expert but @BindingAnnotation insists this behavior by saying

Annotates annotations which are used for binding.

could you elaborate on that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants