如果我们将@Inject 与@Component 一起使用,默认的bean 作用域是什么?

What is the default bean scope if we use @Inject with @Component?

我知道当我们使用 @Autowired@Component 时默认的 bean 作用域是单例的。

但是如果我们将 JSR-330 的 @Inject 与 spring 的 @Component 一起使用(不使用 @Scope@Singleton)呢?

@Inject or @Autowired

没有区别

two annotations works the same way as Spring has decided to support some JSR-299 annotations in addition to their own

注意 JSR-299 构建于 JSR-330

之上

JSR-299 (Java Contexts and Dependency Injection), with Gavin King as lead, uses JSR-330 as base and enhances it significantly with modularization, cross cutting aspects (decorators, interceptors), custom scopes, or type safe injection capabilities. JSR-299 is layered on top of JSR-330

所有 spring beans,如 @Component,默认为单例

singleton bean is quite different from the Singleton pattern as defined in the seminal Gang of Four (GoF) patterns book. The GoF Singleton hard codes the scope of an object such that one and only one instance of a particular class will ever be created per ClassLoader. The scope of the Spring singleton is best described as per container and per bean. This means that if you define one bean for a particular class in a single Spring container, then the Spring container will create one and only one instance of the class defined by that bean definition. The singleton scope is the default scope in Spring