Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.5k views
in Technique[技术] by (71.8m points)

关于springboot bean 一切都是bean

说是springboot中一切都是bean,是指能写成bean的类都要写成bean吗?
譬如我有一个统一的返回类 public class Response{},那么应该注册这个bean,然后再controller中@Autowired吗,我都是retrun new Response(code, message)这样。
我完全明白不同的方法都可以实现,只是问一下优先选择的是哪一种?或是根据不同的class,某些特性的class需要使用bean装配,某些适合直接new?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

-------重新组织了下语言。----------

bean分2种。

spring bean,指的是依赖注入的对象。

java bean,指的是dto之类的数据传输对象,你的Response指的是这种


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...