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

spirngIoc文章的疑问点 #5

Open
Thw841277862 opened this issue Oct 16, 2023 · 1 comment
Open

spirngIoc文章的疑问点 #5

Thw841277862 opened this issue Oct 16, 2023 · 1 comment
Labels
question Further information is requested

Comments

@Thw841277862
Copy link

作者你好,对于SpringIoc这篇文章中发现个别错误问题以及个人疑问:
1.最佳实践模块中MyServiceB类定义了,应该是A和B
2.时序图的布局是否可以优化下,比如点击图片显示一个弹出层这样方便查看。现在的图片操作样式不方便阅读
3.MergedBeanDefinitionPostProcessor 这个合并处理器的用途是啥?一般什么场景下会用到这个?
4.为什么推荐使用@PostConstruct和@PreDestroy注解来做bean的初始化和销毁操作而不是init-method和destroy-method属性,它两不应该是同一套实现机制吗?

@xuchengsheng
Copy link
Owner

xuchengsheng commented Oct 17, 2023

1.最佳实践模块中MyServiceB类定义了,应该是A和B

已解决此问题

2.时序图的布局是否可以优化下,比如点击图片显示一个弹出层这样方便查看。现在的图片操作样式不方便阅读

其实这不是图片,这是markdown中的sequenceDiagram语法,你可以点击右上方的<-->图标进行放大查看,并且可以点击又下脚的几个移动按钮查看。

3.MergedBeanDefinitionPostProcessor 这个合并处理器的用途是啥?一般什么场景下会用到这个?

主要用途是元数据收集与预处理,比如:org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor#postProcessMergedBeanDefinition类中的对@Autowired注解,@value注解进行了元数据收集工作。又比如org.springframework.context.annotation.CommonAnnotationBeanPostProcessor#postProcessMergedBeanDefinition类中对@PostConstruct,@PreDestroy进行了元数据收集工作。

常见应用场景:AOP,自定义注解处理,事务管理

4.为什么推荐使用@PostConstruct和@PreDestroy注解来做bean的初始化和销毁操作而不是init-method和destroy-method属性,它两不应该是同一套实现机制吗?

@PostConstruct和@PreDestroy是JSR-250标准的一部分,这意味着它们不仅仅是Spring特定的,而是Java EE标准的一部分。使用这些注解可以使代码与容器无关,提高代码的可移植性。

具体请查看
@PostConstructhttps://github.com/xuchengsheng/spring-reading/tree/master/spring-jsr/spring-jsr250-postConstruct
@PreDestroy:https://github.com/xuchengsheng/spring-reading/tree/master/spring-jsr/spring-jsr250-preDestroy

@xuchengsheng xuchengsheng added the question Further information is requested label Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants