Skip to main content

Error in Dropwizard Getting Started Sample: WARNING: No injection source found for a parameter of type …

I’m involved in a project that requires the use of Jersey Filters in a Dropwizard project so I thought it’s time I had a play with the Dropwizard framework (or whatever it is) so I asked Google for some suggestions (as you do) and it offered me the Getting Started page.

A great introduction, but I hit a problem when I tried to run the application –


C:\Projects\dwfilters>java -jar target\dwfilters-0.0.1-SNAPSHOT.jar server hello-world.yml

INFO  [2017-03-20 22:31:27,200] org.eclipse.jetty.util.log: Logging initialized @996ms

INFO  [2017-03-20 22:31:27,274] io.dropwizard.server.ServerFactory: Starting hello-world

INFO  [2017-03-20 22:31:27,282] io.dropwizard.server.DefaultServerFactory: Registering jersey handler with root path prefix: /

INFO  [2017-03-20 22:31:27,297] io.dropwizard.server.DefaultServerFactory: Registering admin handler with root path prefix: /

INFO  [2017-03-20 22:31:27,331] org.eclipse.jetty.setuid.SetUIDListener: Opened application@6c5945a7{HTTP/1.1}{0.0.0.0:8080}

INFO  [2017-03-20 22:31:27,331] org.eclipse.jetty.setuid.SetUIDListener: Opened admin@2f05be7f{HTTP/1.1}{0.0.0.0:8081}

INFO  [2017-03-20 22:31:27,335] org.eclipse.jetty.server.Server: jetty-9.2.z-SNAPSHOT

ERROR [2017-03-20 22:31:27,758] org.glassfish.jersey.internal.Errors: Following issues have been detected:

WARNING: No injection source found for a parameter of type public sjw.test.dwfilters.api.Saying sjw.test.dwfilters.resources.HelloWorldResource.sayHello(java.util.Optional) at index 0.



WARN  [2017-03-20 22:31:27,762] /: 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 public sjw.test.dwfilters.api.Saying sjw.test.dwfilters.resources.HelloWorldResource.sayHello(java.util.Optional) at index 0.; source='ResourceMethod{httpMethod=GET, consumedTypes=[], producedTypes=[application/json], suspended=false, suspendTimeout=0, suspendTimeoutUnit=MILLISECONDS, invocable=Invocable{handler=ClassBasedMethodHandler{handlerClass=class sjw.test.dwfilters.resources.HelloWorldResource, handlerConstructors=[org.glassfish.jersey.server.model.HandlerConstructor@400d912a]}, definitionMethod=public sjw.test.dwfilters.api.Saying sjw.test.dwfilters.resources.HelloWorldResource.sayHello(java.util.Optional), parameters=[Parameter [type=class java.util.Optional, source=name, defaultValue=null]], responseType=class sjw.test.dwfilters.api.Saying}, nameBindings=[]}']

I spent a while trying to work out what the problem was and found various suggestions which I couldn’t make sense of in my situation.

To cut a long story short, the problem turned out to be the use of the @QueryParam("name") Optional<String> name parameter in theHelloWorldResource sayHello method.

This is a Java 8 feature and needs additional Java 8 compatibility library. Unfortunately, this then caused another issue, class not found.

I’ll try to solve that second problem another evening, but the first was solved by using the following in the HelloWorldResource class:


@GET
@Timed
public Saying sayHello(@QueryParam("name") String name) {
final String value = String.format(template, name == null ? defaultName : name);
return new Saying(counter.incrementAndGet(), value);
}

Hope this helps someone else save an evening of frustration.

 

 

Tags: ,
Posted in Java, Web Development

Leave a Reply

Your email address will not be published. Required fields are marked *