java - How to check for Request Scope availability in Spring? -


i'm trying setup code behave 1 way if spring's request scope available, , way if said scope not available.

the application in question web app, there jmx triggers , scheduled tasks (i.e. quartz) trigger invocations.

e.g.

@named class mysingletonbean{//this class singleton     // bean request scoped     @inject     private myrequestscopedbean myrequestscopedbean;       /* can invoked either part of request handling        or part of jmx trigger or scheduled task */     public void somemethod(){         if(/* check see if request scope available */){             myrequestscopedbean.invoke();         }else{             //do else         }     } } 

assuming myrequestscopedbean request scoped.

i know can done try-catch around invocation of myrequestscopedbean, e.g.:

@named class mysingletonbean{//this class singleton     // bean request scoped     @inject     private myrequestscopedbean myrequestscopedbean;       /* can invoked either part of request handling        or part of jmx trigger or scheduled task */     public void somemethod(){         try{             myrequestscopedbean.invoke();         }catch(exception e){             //do else         }     } } 

but seems clunky, i'm wondering if knows of elegant spring way interrogate see if request-scoped beans available.

many thanks!

you can use if check described here

spring - current scope

if (requestcontextholder.getrequestattributes() != null)      // request thread 

instead of catching exceptions. looks simplest solution.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -