开发者

How to teach findbugs to understand IoC fields properly?

This is my class (JAX-RS annotated):

@Path("/")
public class Foo {
  @Context
  privat开发者_运维技巧e 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?


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:

@Path("/")
public class Foo {
  private UriInfo uriInfo;
  @Context
  public void setUriInfo(UriInfo info) {
    this.uriInfo = info;
  }
  // ...
}

Now it's correct for findbugs and for OOP design paradigm :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜