Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
42 lines (20 loc) · 1.57 KB

File metadata and controls

42 lines (20 loc) · 1.57 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
@Configuration把一个类作为一个IoC容器它的某个方法头上如果注册了@Bean就会作为这个Spring容器中的Bean
@Scope注解 作用域
@Lazy(true) 表示延迟初始化
@Service用于标注业务层组件
@Controller用于标注控制层组件@Repository用于标注数据访问组件即DAO组件
@Component泛指组件当组件不好归类的时候我们可以使用这个注解进行标注
@Scope用于指定scope作用域的用在类上
@PostConstruct用于指定初始化方法用在方法上
@PreDestory用于指定销毁方法用在方法上
@DependsOn定义Bean初始化及销毁时的顺序
@Primary自动装配时当出现多个Bean候选者时被注解为@Primary的Bean将作为首选者否则将抛出异常
@Autowired 默认按类型装配如果我们想使用按名称装配可以结合@Qualifier注解一起使用如下
@Autowired @Qualifier("personDaoBean") 存在多个实例配合使用
@Resource默认按名称装配当找不到与名称匹配的bean才会按类型装配
@PostConstruct 初始化注解
@PreDestroy 摧毁注解 默认 单例 启动就加载
### Spring中的这几个注解有什么区别@Component@Repository@Service@Controller
1. @Component指的是组件
@Controller@Repository和@Service 注解都被@Component修饰用于代码中区分表现层持久层和业务层的组件代码中组件不好归类时可以使用@Component来标注
2. 当前版本只有区分的作用未来版本可能会添加更丰富的功能
Morty Proxy This is a proxified and sanitized view of the page, visit original site.