java - CGlib-wired bean is recreated each time its method is invoked -


i'm observing strange behavior prototype-scoped class-proxied spring beans. i'm using spring 4.1.2.

i'm creating single bean manually, invoke method 3 times. on each method invocation new class instance gets created - code below prints new id. means cannot reliably store state inside bean.

expected: single instance of class.

observed: each bean method invocation leads new class instance creation.

i've dug cglib - acquires target spring bean bean factory each method invocation. spring bean factory happily creates new bean each time (since prototype bean).

is expected behavior or bug?

@component @scope(value = configurablebeanfactory.scope_prototype, proxymode = scopedproxymode.target_class) public class beanclass1 extends someabstractclass implements i1, i2 {      public void tellme() {         system.out.println(this);     } }  beanclass1 bean = beanfactory.getbean(beanclass1.class); bean.tellme(); bean.tellme(); bean.tellme(); 

i've switched jdk proxies, not recreate beans on each bean method call.

the bean annotated with

@component @scope(value = configurablebeanfactory.scope_prototype) 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -