sharon.biren
sharon.biren

Reputation: 588

How to detect if a bean is instantiated on each HTTP request ?

I'm using the @Scope annotation with value of "request". How do I check if the given object with the "Scope" annotation is instantiated on each http request ? Do the object (bean) have some identifier (hashcode ) ? And, I don't mean the bean id.

Upvotes: 0

Views: 45

Answers (2)

Egan Wolf
Egan Wolf

Reputation: 3573

You gotta believe!

No, I'm kidding. Methods I used so far:

  1. In eclipse if you stop application on a breakpoint you can check the id of every object in Variables tab. Every new instance of object has new id. You probably can find a place in your code that is executed after every (or some) request.
  2. If you can set some fields of this bean via a web page, go and do it and then open the same page in new tab in your web browser. If request scope is working, fields you set should have old values (the one that are set on creation of object).

Maybe these are not uber-pro methods, but may be enough in some cases and you don't have to add anything in your code.

Upvotes: 1

StanislavL
StanislavL

Reputation: 57381

System.identityHashCode(theBeanVariable)

Print the hashes and check the objects are the same or not.

Upvotes: 1

Related Questions