Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How to inject an object to Spring IoC through ApplicationContext? I want to put an POJO Object with some infomation to IoC Container through instand of writing a method and sign annotation @bean I try this way but fail

    @Autowired
    ApplicationContext context;

    @Test
    void contextLoads() {
        GenericWebApplicationContext genericWebApplicationContext = (GenericWebApplicationContext) context;
        genericWebApplicationContext.registerBean(Book.class, XXX);
    }

because registerBean need arguement Class and constructorArgs,i don`t want to just for inject an object to container to create a construct method. just want to inject an existing Object (may i create in a method) to container,not using @bean

question from:https://stackoverflow.com/questions/65651215/how-to-inject-an-object-to-spring-ioc-container-through-applicationcontext

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
154 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...