Given a singleton bean with an injection target, Spring will initialize the bean and inject the field/method/constructor immediately. If that injection target is a prototype bean, Spring will do so exactly once.
Presumably, you want a new prototype bean on each action or event that your singleton handles. You'll need an AOP scoped proxy. This is documented in the Spring chapter on Scoped proxies and dependencies. With a configured scoped proxy, Spring will inject a proxy instead of a prototype bean.
The proxy itself will delegate all calls to it to a prototype bean, a new instance each time.
With annotation configuration, you can configure your @Bean or @Component with
@Scope(scopeName = BeanDefinition.SCOPE_PROTOTYPE, proxyMode = ScopedProxyMode.TARGET_CLASS)
This tells Spring to configure the bean with a proxy that will inherit the target's actual class type and be a prototype.
When you then inject it
@Autowired
private MyPrototypeBean bean;
bean will hold a reference to a proxy object. You can then invoke methods
bean.method();
and that will delegate to a new instance. This means that each call
bean.method();
bean.method();
bean.method();
will operate one a new instance, three new instances in the example above. If you only want one instance to invoke those methods, you can extract it from the proxy. See the solution provided here
MyPrototypeBean target = null;
if (AopUtils.isJdkDynamicProxy(proxy)) {
target = (MyPrototypeBean) ((Advised)proxy).getTargetSource().getTarget();
} // won't work for CGLIB classes AFAIK (gotta search)
@org.springframework.context.annotation.Scope.