
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
import javax.inject.Inject;
import javax.inject.Named;
@Named
public class TransferServiceImpl implements TransferService{
@Inject
public void TransferServiceImpl(@Named("accountRepository") AccountRepository accountRepository ) {
this.accountRepository = accountRepository ;
}
}
import javax.inject.Named;
@Named("accountRepository")
public class JdbcAccountRepository implements AccountRepository {
//...
}
| Spring | JSR 330 | Comments |
|---|---|---|
@Autowired | @Inject | @Inject always mandatory, has no 'required' attribute. |
@Component | @Named | Spring also scan for @Named . |
| @Scope | @Scope | JSR 330 Scope for ,eta annotation and injection point only |
@Scope("singleton") | @Singleton | JSR-330 default scope is like Spring’s prototype. |
@Qualifier | @Named | |
@Value | No equivalent | SpEL specific |
@Required | Redundant | @Inject always required |
@Lazy | No equivalent | Useful when needed, often abused |
Labels: Spring3.0