[英]In JavaEE using asynchronous events logs "No valid EE environment for injection of ObserverClass"
I have implemented a REST endpoint in JavaEE that fires an asynchronous event to trigger a process each time the endpoint is used by a user.我在 JavaEE 中实现了一个 REST 端点,每次用户使用端点时都会触发一个异步事件来触发一个进程。
This all works as intended and the process is triggered asynchronously, but results in a SEVERE
level log: No valid EE environment for injection of TagsProcessor
and I do not understand why.这一切都按预期工作,并且该过程是异步触发的,但会导致
SEVERE
级别的日志: No valid EE environment for injection of TagsProcessor
我不明白为什么。
Is this a bug in Payara?这是Payara中的错误吗? Or am I doing something wrong?
还是我做错了什么?
Here is an example implementation:这是一个示例实现:
Rest endpoint where the event is fired on each login: Rest 端点,每次登录都会触发该事件:
@Path("auth")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@RequestScoped
public class AuthenticationResource {
@POST
@Path("request-jwt")
@PermitAll
@Timed(name = "appV2RequestJwt", absolute = true)
public Response appRequestJwt(RefreshRequest refreshRequest) {
JwtResponse dto;
try {
dto = authenticationProcessor.appRequestJwt(refreshRequest);
//Fire asynchronous event
calculateTagsEvent.fireAsync(new CalculateTagsEvent(refreshRequest.getUsername()));
return Response.ok(dto).build();
} catch (Exception exception) {
LOGGER.log(Level.SEVERE, "Could not request jwt: {}", exception.getMessage());
dto = new JwtResponse(null, INTERNAL_SERVER_ERROR);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(dto).build();
}
}
}
Observer class:观察者 class:
@RequestScoped
public class TagsProcessor {
private static final Logger LOGGER = Logger.getLogger(TagsProcessor.class.getName());
@Inject
private BeanController beanController;
//Observe asynchronous event
public void manageCalculateTagsEvent(@ObservesAsync CalculateTagsEvent event) {
LOGGER.log(Level.WARNING, "Event observed");
beanController.create(new SomeBean());
}
}
This results in the logs:这导致日志:
[#|2022-08-17T06:39:39.461+0000|SEVERE|Payara 5.201||_ThreadID=473;_ThreadName=payara-executor-service-task;_TimeMillis=1660718379461;_LevelValue=1000;| No valid EE environment for injection of TagsProcessor|#]
[#|2022-08-17T06:39:39.473+0000|WARNING|Payara 5.201|TagsProcessor|_ThreadID=473;_ThreadName=payara-executor-service-task;_TimeMillis=1660718379473;_LevelValue=900;| Event observed|#]
So it's working as intended, but is giving me the warning about the injection...所以它按预期工作,但给了我关于注射的警告......
As mentioned in my comment I did try various scopes but in the end it's supposed to be a @Stateless
EJB that can be spawned from a pool without being attached to the client's state.正如我在评论中提到的,我确实尝试了各种范围,但最终它应该是一个
@Stateless
EJB,它可以从池中生成,而无需附加到客户端的 state。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.