Best Practise of injecting applicationContext in Spring3

后端 未结 5 1596
陌清茗
陌清茗 2020-12-14 12:09

As in the title above, I am confused about pros cons between injecting applicationContext by directly @Autowired annnotation or implementing ApplicationContextAware interfac

5条回答
  •  無奈伤痛
    2020-12-14 12:39

    If you need to get a prototype in a singleton then you can use method injection. Basically, you create an abstract method that returns the object you need and spring will return the prototype everytime you call that method. You define the "lookup-method" in your spring config. Here are some links: http://docs.spring.io/spring/docs/1.2.9/reference/beans.html#beans-factory-method-injection http://java.dzone.com/articles/method-injection-spring

提交回复
热议问题