Java:JSR330:修订间差异

来自WHY42
imported>Soleverlee
以“[https://jcp.org/en/jsr/detail?id=330 JSR330]定义了Java依赖注入的标准。主要提供了一系列的定义([http://docs.oracle.com/javaee/6/api/javax/inje...”为内容创建页面
 
imported>Soleverlee
第7行: 第7行:
*Singleton Identifies a type that the injector only instantiates once.
*Singleton Identifies a type that the injector only instantiates once.
=@Inject=
=@Inject=
see [https://dzone.com/articles/java-ee6-cdi-named-components this] post
<source lang="java">
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;
</source>
=@Named=
=@Named=
=@Singleton=
=@Singleton=

2016年11月28日 (一) 01:50的版本

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>