简体   繁体   English

为Private静态内部类注入bean

[英]Injecting bean for Private static inner class

Let say I have a private static inner class. 假设我有一个私有的静态内部类。 How can I autowire it inside it's parent class? 如何在它的父类中自动装配它?

Autowiring a public inner class is possible. 自动装配公共内部类是可能的。 But I'm unable to find a way to Autowire a private inner class. 但是我找不到自动连线私有内部类的方法。

public class Parent {

@Autowire
private InnerChild innerChild;

private static class InnerChild {

}

}

Thanks in advance 提前致谢

    @Component
    public class Parent {

        @Autowired
        private InnerChild innerChild;

        @Component
        private static class InnerChild {

        }

    }

This way it should work, but outside of its parent class you can't access InnerChild private class, even if you have a public method in Parent class exporting it, because it is accessible only by Parent class. 这样就可以正常工作,但是,即使您在父类的导出方法中有一个公共方法,也不能在其父类之外访问InnerChild私有类,因为它只能由父类访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM