UPDATE:
The problem is a little more complicated than I thought. In fact, lazy is the default behavior for beans with a prototype. I stumbled a bit, and I was able to reproduce your problem and find a solution. So what is the problem?
You probably have <aop:scoped-proxy/> enabled or ( @ComponentScan(scopedProxy=...) ). During a context update, Spring wraps your bean prototype ( ClosedMetricSubscriberFeed ) with a polarized proxy. It uses a proxy class because (a) the proxy classes are selected or (b) the class has no interfaces.
A class-based proxy is basically a subclass of the CGLIB of your bean, which should call (due to JVM rules) the base class constructor. The generated CGLIB class always calls the no-arg constructor.
I know this sounds complicated, here is what you can do:
Disable <aop:scoped-proxy/> . Similar.
Provide the no-arg dummy constructor and just in case condemn it. Unfortunately, you will have to detect such dummy cases in manunally. Note that in this case the class will be of type: `.
Extract the interface from your class and use the interfaces for trusted proxies:
.
@Scope( value = ConfigurableBeanFactory.SCOPE_PROTOTYPE, proxyMode = ScopedProxyMode.INTERFACES)
Old answer:
Use lazy initialization using the @Lazy annotation or lazy-init="true" (see 4.4.4 Lazy-initialized beans in the reference documentation).
<bean id="proto" class="MyPrototype" scope="prototype" lazy-init="true"/>
or
@Service @Scope("prototype") @Lazy public class MyPrototype {}
source share