java 如何创建一个内部类的Spring Bean?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11886526/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 06:47:17  来源:igfitidea点击:

How to create a Spring Bean of a Inner class?

javaspring

提问by Rubens Mariuzzo

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

我想创建一个内部类的 Spring Bean。如果我有以下内部类B

package x.y.z;

public class A {
    public class B { }
}

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

我想在我的 XML 配置文件中创建 bean 实例。

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

回答by Rubens Mariuzzo

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.

这将起作用。