No injection source found for a parameter
See original GitHub issueHello,
I am having troubles adding Basic Authentication to my Dropwizard application. I am using DW 0.8.1 I have followed this artciles http://java.dzone.com/articles/getting-started-dropwizard-0 but I keep getting the following
WARN [2015-06-17 08:55:10,030] /: unavailable
! org.glassfish.jersey.server.model.ModelValidationException: Validation of the application resource model has failed during application initialization.
! [[FATAL] No injection source found for a parameter of type
Initially I thought that the issue was related to https://github.com/dropwizard/dropwizard/issues/783 but my configuration follows the ones in the doc:
@PATCH
@Path("/books/{id}")
@Consumes("application/json")
public void updateTitle(
@Auth User user,
@PathParam("id") String bookId, BookBean bookBean) {
}
the application configuration
environment.jersey().register(AuthFactory.binder(
new BasicAuthFactory<>(
new UserBasicAuthenticator(configuration.getAuthenticationConfiguration().getUser(),
configuration.getAuthenticationConfiguration().getPassword()),
"SECURITY REALM",
User.class)));
and UserBasicAuthenticator is
...
public Optional<User> authenticate(BasicCredentials credentials)
throws AuthenticationException {
if (password.equals(credentials.getPassword())
&& user.equals(credentials.getUsername())) {
return Optional.of(new User(credentials.getUsername()));
} else {
return Optional.absent();
}
}
...
Issue Analytics
- State:
- Created 8 years ago
- Comments:12 (4 by maintainers)
Top Results From Across the Web
No injection source found for a parameter of type public javax ...
I was trying to use a user defined object as a query parameter and from the answer that's usually not allowed unless it...
Read more >No injection source found for a parameter of type public javax ...
No injection source found for a parameter of type public javax.ws.rs.core. ... InputStream), parameters=[Parameter [type=class java.io.
Read more >SpringBoot: No injection source found for a parameter
No injection source found for a parameter of type public javax.ws.rs.core.Response com.example.jersey.UserResource.
Read more >WARNING: No injection source found for a parameter of type
I'm involved in a project that uses Dropwizard so I thought it's time I had a play with the Dropwizard framework (or whatever...
Read more >No injection source found for a parameter of type public java ...
Hello, When I trying to run application using Jdeveloper, I am getting the below error.
Read more >
Top Related Medium Post
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Top Related StackOverflow Question
For any future readers, here is the reason for the error.
When Jersey starts up, it builds a model of all the resources. In the model includes all the parameters. The Jersey validates the model. It does this to benefit us, by making sure that the all the models can be processed correctly during a request. Part of the validation process consists of validating the parameters. There are some rules that guide what parameters we can have. For instance we can only have one entity body parameters (excluding things like @FormParam and @FormDataParam). The entity parameter is generally the parameter with no annotation.
The way the validation works for parameters is that it for each parameter, Jersey traverses all the
ValueFactoryProviders and it passes theParameter(which is a model of the actual parameter) to theValueFactoryProvider, and expects aFactoryto be returned. If aFactoryis not returned from oneValueFactoryProvider, then it goes on to the next until either aFactoryis returned, or all theValueFactoryProviders have been checked and noFactoryhas been returned by any of them. In which case Jersey throws aModelValidationException, as there is noValueFactoryProviderto handle that parameter. Things like@PathParam,@QueryParam,@FormParamand other framework parameter annotations have their ownValueFactoryProviders automatically installed.That being said when traversing the parameters, Jersey give one pass for a single entity parameter. So for the error to occur in an example such as
one of those parameter passes are failing. The
OrcamentoRepresentationparameter will be given the entity parameter pass, but theUserfails as there is noValueFactoryProviderthat returns aFactoryfor that parameter.But the thing is, the
AuthValueFactoryProvideris the component that provides the value for the@Auth Userparameter. You can see here in the sourcehttps://github.com/dropwizard/dropwizard/blob/2565a66fbb62e28c8e7ac2754be14e594fd1b445/dropwizard-auth/src/main/java/io/dropwizard/auth/AuthValueFactoryProvider.java#L53-L59
where it actually returns the
Factory. The only thing that could cause it to fail is if the following condition were to failBut it shouldn’t fail, as the
principalClassis obtained through our passing the class to theAuthValueFactoryProvider.Binder<>(User.class);. As long as theprincipalClassand the actual parameter class are the same, the condition should pass.@ivanjeukens I’ve tested with your exact configuration with 0.9.2, and it works fine. Maybe a clean and build. Or maybe the problem is somewhere else. I don’t know. But I hope I gave you some idea of what the problem is.
I ran into a similar issue simply importing the wrong annotation:
import javax.websocket.server.PathParam; import javax.ws.rs.PathParam;
It may not be the case for you but I lost a few days on it.