Spring 通过构造器自动注入所有子类

目的:通过反射的方式动态调用子类方法

代码示例:

1
2
3
4
5
6
7
8
9
@Component
public class RequestContent {
private final Map<Class<? extends RequestHandler>, RequestHandler> handlerMap = new ConcurrentHashMap();

@Autowired
public RequestContext(Map<String, RequestHandler> handlers) {
handler.forEach((k, v) -> this.handlerMap.put(v.getClass(), v));
}
}

Spring 通过构造器自动注入所有子类
https://probiecoder.cn/spring/construct_autowired_subclass.html
作者
duwei
发布于
2025年4月22日
许可协议