Implement a simple factory pattern with Spring 3 annotations

前端 未结 11 1999
旧巷少年郎
旧巷少年郎 2020-12-12 10:37

I was wondering how I could implement the simple factory pattern with Spring 3 annotations. I saw in the documentation that you can create beans that call the factory class

11条回答
  •  时光取名叫无心
    2020-12-12 11:27

    You could also declaratively define a bean of type ServiceLocatorFactoryBean that will act as a Factory class. it supported by Spring 3.

    A FactoryBean implementation that takes an interface which must have one or more methods with the signatures (typically, MyService getService() or MyService getService(String id)) and creates a dynamic proxy which implements that interface

    Here's an example of implementing the Factory pattern using Spring

    One more clearly example

提交回复
热议问题