Spring get current ApplicationContext

后端 未结 11 927
陌清茗
陌清茗 2020-11-28 20:04

I am using Spring MVC for my web application. My beans are written in \"spring-servlet.xml\" file

Now I have a class MyClass and i want to

11条回答
  •  臣服心动
    2020-11-28 20:44

    If you're implementing a class that's not instantiated by Spring, like a JsonDeserializer you can use:

    WebApplicationContext context = ContextLoader.getCurrentWebApplicationContext();
    MyClass myBean = context.getBean(MyClass.class);
    

提交回复
热议问题