I'm following the 22.1. Implementing Custom Injection Provider paragraph
https://jersey.java.net/documentation/latest/user-guide.html#deployment
I defined my classes as below:
public class PrincipalConfig extends ResourceConfig {
public PrincipalConfig() {
packages("com.vex.klopotest.secured,com.klopotek.klas.auth.injection");
register(new MyBinder());
}
}
Where MyBinder is :
Public class MyBinder extends AbstractBinder implements Factory<KasPrincipal> {
@Override
protected void configure() {
bindFactory(this).to(MyInjectable.class).in(RequestScoped.class);
bind(KasPersistenceDaoInjectionResolver.class)
.to(new TypeLiteral<InjectionResolver<KasPersistenceDaoAnnot>>(){})
.in(Singleton.class);
}
@Override
public MyInjectable provide() {
// TODO Auto-generated method stub
return new MyInjectable();
}
@Override
public void dispose(MyInjectable instance) {
// TODO Auto-generated method stub
}
}
and this is my simple annotation:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface MyAnnot {
}
i wanto to use the annotation in my res service:
@Path("modelORA")
public class ModelRetrieverORA {
@Context
SecurityContext securityContext;
@Context
private UriInfo uriInfo;
@MyAnnot
private Myinjectable Principal;
in my web.xml i deployed Jersey servlet container (am i wrong) and javax.ws.rs.Application by this configuration code:
<servlet>
<servlet-name>com.my.package.injection.PrincipalConfig</servlet-name>
</servlet>
<servlet-mapping>
<servlet-name>com.my.package.injection.PrincipalConfig</servlet-name>
<url-pattern>/rest</url-pattern>
</servlet-mapping>
Going into debug mode i see that when invoking my rest service the provide method is never called... indeed is always null.
Where am i wrong? I m working on a jboss Wildfly 9.0 and using Jersey 2.21 library
i found a solution:
1) In web.xml add:
this way i can exclude resteasy from scanning my war.
Then use these deployment instructions:
This is because the previous deployment method was for Servlet specs 3.0.
The injection now works.
It may because of conflicts in rest web-service implementation. you are using jersey implementation of rest-ws but wildfly comes with resteasy (rest-ws implementation). i suggest you to go with resteasy if you are using wildfly with minimal changes in your web.xml. Be sure to remove/comment your jersey specific configurations.
You also need to remove jersey related jars from your WEB-INF/libs directory.