Hello, I am creating an application using dropwizard using jersey 2.16 internally as a REST API framework.
For the entire application for all resource methods, I need some information to parse this information, I defined a user filter as shown below
@java.lang.annotation.Target(ElementType.PARAMETER) @java.lang.annotation.Retention(RetentionPolicy.RUNTIME) public @interface TenantParam { }
Factory tenant is defined below
public class TenantFactory implements Factory<Tenant> { private final HttpServletRequest request; private final ApiConfiguration apiConfiguration; @Inject public TenantFactory(HttpServletRequest request, @Named(ApiConfiguration.NAMED_BINDING) ApiConfiguration apiConfiguration) { this.request = request; this.apiConfiguration = apiConfiguration; } @Override public Tenant provide() { return null; } @Override public void dispose(Tenant tenant) { } }
I really did not implement the method, but the structure is higher. There is also a TenantparamResolver
public class TenantParamResolver implements InjectionResolver<TenantParam> { @Inject @Named(InjectionResolver.SYSTEM_RESOLVER_NAME) private InjectionResolver<Inject> systemInjectionResolver; @Override public Object resolve(Injectee injectee, ServiceHandle<?> serviceHandle) { if(Tenant.class == injectee.getRequiredType()) { return systemInjectionResolver.resolve(injectee, serviceHandle); } return null; } @Override public boolean isConstructorParameterIndicator() { return false; } @Override public boolean isMethodParameterIndicator() { return true; } }
Now in my resource method I do as below
@POST @Timed public ApiResponse create(User user, @TenantParam Tenant tenant) { System.out.println("resource method invoked. calling service method"); System.out.println("service class" + this.service.getClass().toString()); //DatabaseResult<User> result = this.service.insert(user, tenant); //return ApiResponse.buildWithPayload(new Payload<User>().addObjects(result.getResults())); return null; }
This is how I configure the application
@Override public void run(Configuration configuration, Environment environment) throws Exception { // bind auth and token param annotations environment.jersey().register(new AbstractBinder() { @Override protected void configure() { bindFactory(TenantFactory.class).to(Tenant.class); bind(TenantParamResolver.class) .to(new TypeLiteral<InjectionResolver<TenantParam>>() {}) .in(Singleton.class); } }); }
Problem while starting the application. I am getting below the error.
WARNING: No injection source found for a parameter of type public void com.proretention.commons.auth.resources.Users.create(com.proretention.commons.api.core.Tenant,com.proretention.commons.auth.model.User) at index 0.
and there is a very long stack stack and description
Below is the signature of pojo's ad
public class User extends com.company.models.Model {
There are no annotations for the User class. A model is a class that defines only one property identifier of type long, as well as annotations in the model class
When I remove the User parameter from above, create a resource method, it works fine, and when I remove TenantParam, it also works fine. The problem only occurs when I use both User and TenantParam
- What am I missing here? How to solve this error?
edited
I just tried with two special injections of method parameters that also don't work
@POST @Path("/login") @Timed public void validateUser(@AuthParam AuthToken token, @TenantParam Tenant tenant) { }
- What am I missing here? Is this a limitation in knitwear?