Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spring中,以 Aware结尾的类,都是干什么用的?能举例说明么? #1

Open
lycying opened this issue Dec 4, 2020 · 4 comments

Comments

@lycying
Copy link
Member

lycying commented Dec 4, 2020

日期:2020-12-04
问题:spring中,以 Aware结尾的类,都是干什么用的?能举例说明么?
标签:Spring,初级

@lycying
Copy link
Member Author

lycying commented Dec 4, 2020

Aware就是感知的意思,一般以该单词结尾的类,都实现了Aware接口,该接口就是一个标记,用于表示其子类是可以被回调的。具体回调方法由子类实现,比如ApplicationContextAware

@lycying
Copy link
Member Author

lycying commented Dec 4, 2020

实现了Aware结尾的接口类可以获得相应的spring框架里的相关实例,实际工作中我常用的是ApplicationContextAware获取到spring的上下文,再由此获得相关的bean,这也是获取注入bean的一种方法,在某些无法autowired的情况下使用

@lycying
Copy link
Member Author

lycying commented Dec 4, 2020

这个其实非常常用。可惜的是Spring没有默认提供这种Holder,结果每个项目里都要做这么一个工具类。非常的的不理解

@lycying
Copy link
Member Author

lycying commented Dec 10, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant