我正在关注22.1。实现自定义注入提供程序段落
https://jersey.java.net/documentation/latest/user-guide.html#deployment
我将我的课程定义如下:
public class PrincipalConfig extends ResourceConfig {
public PrincipalConfig() {
packages("com.vex.klopotest.secured,com.klopotek.klas.auth.injection");
register(new MyBinder());
}
}
MyBinder 在哪里:
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
}
}
这是我的简单注释:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface MyAnnot {
}
我想在我的 res 服务中使用注释:
@Path("modelORA")
public class ModelRetrieverORA {
@Context
SecurityContext securityContext;
@Context
private UriInfo uriInfo;
@MyAnnot
private Myinjectable Principal;
在我的 web.xml 中,我通过以下配置代码部署了 Jersey servlet 容器(我错了)和 javax.ws.rs.Application:
<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>
进入调试模式,我看到在调用我的休息服务时,永远不会调用提供方法......确实总是为空。
我哪里错了?我正在使用 jboss Wildfly 9.0 并使用 Jersey 2.21 库