跳转到内容

欢迎来到Riguz的小站!这是一个私人wiki,用来记录一些我的笔记。

Java:JSR330

来自WHY42
imported>Soleverlee2016年11月28日 (一) 01:50的版本 (→@Inject)

JSR330定义了Java依赖注入的标准。主要提供了一系列的定义(javax.inject.*):

  • Provider<T> Provides instances of T.
  • Inject Identifies injectable constructors, methods, and fields.
  • Named String-based qualifier.
  • Qualifier Identifies qualifier annotations.
  • Scope Identifies scope annotations.
  • Singleton Identifies a type that the injector only instantiates once.

@Inject

see this post

public interface Payment {
    void pay(BigDecimal amount);
}

public class CashPaymentImpl implements Payment {

    private static final Logger LOGGER = Logger.getLogger(CashPaymentImpl.class.toString());

    @Override
    public void pay(BigDecimal amount) {
        LOGGER.log(Level.INFO, "payed {0} cash", amount.toString());
    }
}

@Inject private Payment payment;

@Named

@Singleton

@Qualifier

@Scope

Provider<T>