Spring | javax.inject.* | javax.inject restrictions / comments |
---|---|---|
@Autowired | @Inject | @Inject has no 'required' attribute |
@Component | @Named | |
@Scope("singleton") | @Singleton | jsr-330 default scope is like Spring's
|
@Qualifier | @Named | |
@Value | - | no equivalent |
@Required | - | no equivalent |
@Lazy | - | no equivalent
|
使用@Named和@Inject的时候需要
配置文件中加上要扫描的包
<beans> <context:component-scan base-package="org.example"/> </beans>
Java-based container configuration
@Configuration public class AppConfig { @Bean public MyService myService() { return new MyServiceImpl(); } }
等同于
<beans> <bean id="myService" class="com.acme.services.MyServiceImpl"/> </beans>