最近 接触一个电商系统后台,须要了解支付模块的开发时候,发现了这样一段有趣的代码java
@Inject private List<PaymentPlugin> paymentPlugins = new ArrayList<>(); @Override public List<PaymentPlugin> getPaymentPlugins() { Collections.sort(paymentPlugins); return paymentPlugins; }
业务层getPaymentPlugins()方法中没有任何查询.可是 paymentPlugins居然有值,spring
public abstract class PaymentPlugin implements Comparable<PaymentPlugin> {
查询了系统各个配置以及SQL语句 没有相关的配置啊ide
在多方google 百度下,了解了google
原来是spring @Inject 注解能够注入抽象类 或者接口的子类的集合code
子类配置:接口
@Component("alipayPagePaymentPlugin") public class AlipayPagePaymentPlugin extends PaymentPlugin {
很佩服这种思惟.ip