0

I get a null pointer when I try to access a method in a Spring Bean child class, for example, in class A below:

new B().methodB();

How can I properly extend Spring Bean and acess the Child Class?

@Component
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS, value = "prototype")
class A {
    @Autowired
    protected Object objectl

    public void methodA() {
        new B().methodB();
    }

    public void doStuff() {
        System.out.println("Successfully called...");
    }
}

class B extends B {
    public void methodB() {
        objectl.doStuff();
    }
}

UPDATE:

The problem is that I'm trying to to create an Array Objcet of B, something like B[] b = new B[size], but I can't figure how to from a Spring Bean.

Program-Me-Rev
  • 6,184
  • 18
  • 58
  • 142
  • Why do you think Spring would be involved in the expression `new B().methodB();`? – Sotirios Delimanolis May 22 '15 at 17:31
  • @Sotirios Delimanolis: Like I said in the Update, the problem is that I'm trying to to create an Array Objcet of B, something like B[] b = new B[size], but I can't figure how to from a Spring Bean. – Program-Me-Rev May 22 '15 at 17:58
  • If you want Spring to be involved, you'll need to get the **beans** from a **bean context**, that is Spring's `ApplicationContext`. You can't be initializing them yourself. – Sotirios Delimanolis May 22 '15 at 17:59

0 Answers0