将@RequestScoped bean注入ContainerRequestFilter

时间:2019-02-08 14:41:37

标签: java rest java-ee jersey singleton

我正在尝试在ContainerRequestFilter中将带有“ @RequestScoped”的bean注入,但是它引发了“ UnsatisfiedDependencyException”错误,我到处都在寻找解决方案,但是我始终无法解决问题,请帮忙,谢谢。

这是我的代码

 @RequestScoped
public class SimpleKeyGenerator implements KeyGenerator{

    @Override
    public Key generarKey() {
        String keyString="simplekey";
        Key key=new SecretKeySpec(keyString.getBytes(),0,keyString.getBytes().length,"DES");
        return key;
    }

}

ContainerRequestFilter

    @Provider
@TokenNecesario
@Priority(Priorities.AUTHENTICATION)
public class filtroValidacionToken implements ContainerRequestFilter{

    @Inject
    private KeyGenerator keyGenerator;//UnsatisfiedDependencyException HERE



    @Override
    public void filter(ContainerRequestContext requestContext) throws IOException {
       requestContext.abortWith(Response.status(Response.Status.UNAUTHORIZED).build());
    }

}

0 个答案:

没有答案