mardi 31 mars 2015

How to check for Request Scope availability in Spring?

I'm trying to setup some code that will behave one way if spring's request scope is available, and another way if said scope is not available.


The application in question is a web app, but some things can be initiated by Quartz Scheduler or JMX


E.g.



@Named
class MySingletonBean{
@Inject
private MyRequestScopedBean myRequestScopedBean;

public void someMethod(){
if(/* your awesome solution here */){
myRequestScopedBean.invoke();
}else{
//do something else
}
}
}


Assuming myRequestScopedBean is request scoped.


I know this can be done with a try-catch around the invocation of myRequestScopedBean but that seems really clunky, so I'm wondering if anyone knows of an elegant Spring way to interrogate something to see if request-scoped beans are available.


Many thanks!


Aucun commentaire:

Enregistrer un commentaire