`

spring 的一些 注解

阅读更多

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'sprototype. However, in order to keep it consistent with Spring's general defaults, a jsr-330 bean declared in the Spring container is asingletonby default. In order to use another scope thansingleton, you should use Spring's@Scopeannotation.

javax.injectalso provides a@Scopeannotation. Nevertheless, this one only aims to be used for creating your own annotations.

@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>


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics