|
From: Bill B. <bb...@re...> - 2008-08-22 17:57:19
|
Paulo Siqueira wrote:
> Hi Martin,
>
> Almost like that, but the problem is that the resource is SOMETIMES
> injected (which I couldn't take any sense out of it yet).
>
> So, it would be like this:
>
> @Path("/")
> public class MyResourceA {
>
> @Resource
> Context ctx; // this is SOMETIMES injected
>
> @Path("foo")
> public MyResourceB produceB() {
> return new MyResourceB();
> }
>
> }
>
> If I print the ctx field inside produceB, it will sometimes be null, and
> sometimes be a valid object.
>
MyResourceA should be a singleton right? Only instantiated once? I
just can't see this as a Resteasy problem. Can you put in a default
constructor and see how many times an instance of MyResourceA is
instantiated? Another thing maybe could be to use setter injection and
log there to see how many times the setter is call. A final thing,
create some random ID per instance and print it out to see if you have
different instances.
i.e.
@Path("/")
@Service
public class MyResourceA {
private long id = System.currentTimeMillis();
public MyResourceA() {
System.out.println("Instantiated: " + id);
}
@Resource
public void setCtx(Context ctx) {
System.out.pritln("setCtx called on: " + id);
this.ctx = ctx;
}
@Path("foo")
public MyResourceB produceB() {
System.out.pritln("produceB called on: " + id);
return new MyResourceB();
}
}
--
Bill Burke
JBoss, a division of Red Hat
http://bill.burkecentral.com
|