将一个类声明为 Spring Bean 的注解有:
@Component: 通用的注解,可标注任何类为 Spring 组件,适用于任何层次的组件。@Repository: 用于持久层,主要用于 DAO 类。@Service: 用于服务层,涉及业务逻辑,依赖于 DAO 层。@Controller: 用于 Spring MVC 控制层,处理用户请求并调用 Service 层。@Configuration: 用于标识配置类,通常与@Bean一起使用,定义了一些 bean 的配置。@Bean: 用于方法级别上,标识方法返回一个 bean 实例,通常在配置类中使用。@Scope: 用于指定 bean 的作用域,常见的取值有"singleton"和"prototype"。@Qualifier: 用于指定具体的 bean 名称,解决自动装配时的歧义性问题。@Value: 用于注入简单的数值、字符串等。