Runtime dependency injection with Spring

前端 未结 3 666
我寻月下人不归
我寻月下人不归 2020-12-14 21:24

My current project is leveraging Spring, and our architect has decided to let Spring manage Services, Repositories and Factory objects, but NOT domain objects. We are closel

3条回答
  •  悲哀的现实
    2020-12-14 22:02

    I suggest you read the section in the Spring docs concerning Using AspectJ to dependency inject domain objects with Spring.

    It's interesting that you said "I could use AOP to inject dependencies, but then i am not leveraging spring's infrastructure, " considering that AOP is a core part of Spring's infrastructure. The two go very well together.

    The above link allows you to have Spring's AOP transparently inject dependencies into domain objects that are creating without direct reference to the Spring infrastructure (e.g. using the new operator). It's very clever, but does require some deep-level classloading tinkering.

提交回复
热议问题