Friday, 15 April 2011

java - Override a spring scope in a child bean -



java - Override a spring scope in a child bean -

i have defined spring bean extending bean defined singleton. means this:

<bean id="achildbean" parent="aparentbean"> <!-- ......-> </bean>

now, wonder if define scope "request" in bean. know kid bean inherits scope of parent, i'm not sure logically work. when tested this, spring spring generated exception below:

error creating bean name 'achildbean': scope 'request' not active current thread; consider defining scoped proxy bean if intend refer singleton; nested exception java.lang.illegalstateexception: no thread bound request found: referring request attributes outside of actual web request, or processing request outside of receiving thread? ...

so, wonder if such action. and, if definition of scoped bean solve problem ?

thanks in advance answers..

quote documentation:

a kid bean definition inherits constructor argument values, property values, , method overrides parent, alternative add together new values. initialization method, destroy method, and/or static mill method settings specify override corresponding parent settings.

the remaining settings taken kid definition: depends on, autowire mode, dependency check, singleton, scope, lazy init.

so, bean "request" scoped, "request" scope makes sense in web environment. see here documentation of "request" scope.

java spring scope

No comments:

Post a Comment