如何教 findbugs 正确理解 IoC 字段?
这是我的类(JAX-RS注释):
@Path("/")
public class Foo {
@Context
private UriInfo uriInfo;
// ...
}
这就是 findbugs 所说的:
Unwritten field: com.XXX.Foo.uriInfo
这是真的,该字段是未写入的,但它是注入的通过 JAX-RS servlet。我认为我在这里做错了什么,但是如何解决这个问题呢?
This is my class (JAX-RS annotated):
@Path("/")
public class Foo {
@Context
private UriInfo uriInfo;
// ...
}
This is what findbugs says:
Unwritten field: com.XXX.Foo.uriInfo
It's true, the field is unwritten, but it is injected by JAX-RS servlet. I think that I'm doing something wrong here, but how to solve the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
到目前为止我所了解的是 findbugs 是正确的。它告诉我这个变量无法从类外部访问,并且我的注释在 OOP 方面无效。 JAX-RS servlet 必须打破字段访问限制才能注入
UriInfo
。我必须给他一个进入这个领域的合法途径:现在对于 findbugs 和 OOP 设计范式来说这是正确的:)
What I've understand so far is that findbugs is right. It tells me that this variable is not accessible from outside of the class, and my annotation is not valid in terms of OOP. The JAX-RS servlet will have to break field access restrictions in order to inject
UriInfo
. I have to give him a legal way to this field:Now it's correct for findbugs and for OOP design paradigm :)