在具有匿名实现的抽象组件上使用范围原型

时间:2016-11-01 13:40:18

标签: java spring

我有以下情况:

@Component
@Scope("prototype")
public abstract class AbstractA {
    protected abstract String getData();
}

现在我将要求以动态方式创建此类的实例(使用匿名内部类)。如:

@Component
public class B {
    public void some_method() {
        //Obviously this is wrong, I want to be able to do this through Spring/beans.
        new AbstractA() {
            protected abstract String getData() {
                return "abc";
            }
        }
    }
}

在这种情况下,我如何才能获得原型bean的实例?

0 个答案:

没有答案