注入的豆在我的quarkus扩展中无效
我有一个非常简单的Quarkus扩展名,它定义了一个容器RequestFilter来过滤身份验证并将数据添加到自定义AuthenticationContext。
这是我的代码:
runtime/AuthenticationContext.java
public interface AuthenticationContext {
User getCurrentUser();
}
Runtime/AuthenticationContextimpl.java
@RequestScoped
public class AuthenticationContextImpl implements AuthenticationContext {
private User user;
@Override
public User getCurrentUser() {
return user;
}
public void setCurrentUser(User user) {
this.user = user;
}
}
runtime/myFilter.java
@ApplicationScoped
public class MyFilter implements ContainerRequestFilter {
@Inject
AuthenticationContextImpl authCtx;
@Override
public void filter(ContainerRequestContext requestContext){
// doing some stuff like retrieving the user from the request Context
// ...
authCtx.setCurrentUser(retrievedUser)
}
}
deployment/myProcessor.java < /code>:
class MyProcessor {
//... Some stuff
@BuildStep
AdditionalBeanBuildItem createContext() {
return new AdditionalBeanBuildItem(AuthenticationContextImpl.class);
}
}
我在authctx.setcurrentuser(retereduser)
呼叫(永远不会注入authctx)中有一个无效的指针异常
。
谢谢
I have a quite simple quarkus extension which defines a ContainerRequestFilter to filter authentication and add data to a custom AuthenticationContext.
Here is my code:
runtime/AuthenticationContext.java
public interface AuthenticationContext {
User getCurrentUser();
}
runtime/AuthenticationContextImpl.java
@RequestScoped
public class AuthenticationContextImpl implements AuthenticationContext {
private User user;
@Override
public User getCurrentUser() {
return user;
}
public void setCurrentUser(User user) {
this.user = user;
}
}
runtime/MyFilter.java
@ApplicationScoped
public class MyFilter implements ContainerRequestFilter {
@Inject
AuthenticationContextImpl authCtx;
@Override
public void filter(ContainerRequestContext requestContext){
// doing some stuff like retrieving the user from the request Context
// ...
authCtx.setCurrentUser(retrievedUser)
}
}
deployment/MyProcessor.java
:
class MyProcessor {
//... Some stuff
@BuildStep
AdditionalBeanBuildItem createContext() {
return new AdditionalBeanBuildItem(AuthenticationContextImpl.class);
}
}
I have a Null Pointer Exception in authCtx.setCurrentUser(retrievedUser)
call (authCtx is never injected)
What am I missing here ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
索引扩展名的
Runtime
模块解决了问题。如
Indexing the
runtime
module of the extension fixes the problem.There are multiple ways to do that as mentioned in https://stackoverflow.com/a/55513723/2504224