java向其他bean注入工厂类
我有一个工厂类,我想知道是否有可能将AnimalMapper
工厂类注入到其他需要它的bean中
animalapper工厂类
public static Mapper create(final String type) {
if (type.equalsIgnoreCase("dog")) {
return new DogMapper();
} else if (type.equalsIgnoreCase("cat")) {
return new CatMapper();
} ...
}
目前我正在使用AnimalMapper.create(...)
# 1 楼答案
请参阅参考文档:http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/pdf/spring-framework-reference.pdf
关于bean定义中的工厂方法的第43-43页
# 2 楼答案
你想要实现什么?类似于CDI的内容:
# 3 楼答案
下面是示例代码
我不确定你们是否在寻找这个问题,但若你们能进一步澄清这个问题,那个么可以添加更多细节