Rubens Mariuzzo
Rubens Mariuzzo

Reputation: 29241

How to create a Spring Bean of a Inner class?

I would like to create a Spring Bean of a Inner class. If I have the following inner class B:

package x.y.z;

public class A {
    public class B { }
}

I would like to create bean instance in my XML configuration files.

<bean class="x.y.z.A.B" name="innerBean" />

Upvotes: 27

Views: 17588

Answers (1)

Rubens Mariuzzo
Rubens Mariuzzo

Reputation: 29241

You cannot access your public static inner class with the dot (.) notation, instead, use the currency ($). An example:

<bean class="x.y.z.A$B" name="innerBean" />

This will work.

Upvotes: 41

Related Questions