LD is tigger,CG are not brothers, throw the pot and shine.
The competition in the workplace is always calm on the surface, but in fact it is turbulent.
talk is cheap, show me the code,Keep progress,make a better result.
Survive during the day and develop at night。
目录
概述
今天遇到了一个问题,有点困惑,这里没做写demo实验,而是在现场debug
需求:
Spring 使用@compont 注入的bean 的名称规范是什么?
设计思路
无
实现思路分析
1. 提出问题
2.发现问题
拓展Demo实现
无
相关工具如下:
直接在现场debug,在beanFactory 视图下看到了Spring容器注册的Bean。
实验效果:
通过比较然后百度找到了一篇文章,
分析:
1.使用spring注释形式注入bean,通过@Component、@Repository、 @Service和@Controller注释类,文档中说“注解如果没有指定bean的名字,默认为小写开头的类名”。例如类名是MyClass,则spring返回myClass的bean名。 但是如果类名…
正文
使用spring注释形式注入bean,通过@Component、@Repository、 @Service和@Controller注释类,文档中说“注解如果没有指定bean的名字,默认为小写开头的类名”。例如类名是MyClass,则spring返回myClass的bean名。
但是如果类名前两个字母都是大写,则返回的bean名也是大写,即类名是MYClass,bean名也是MYClass
3.正是这个原因我的数据库中有Stand开头的数据库记录,恰好又调用了这条记录,所以根据代码是找不到对应的大写的bean的,改了之后就不报错了。但是数据是否正确导入我并没有测试,应该是不行的。但这是导出的问题了,但是我换成JSONExport对象就可以了。
4.原来可以导出的数据库为啥可以用呢?因为是前2个字母是大写的,返回了对应的对象了。为啥可以直接导出呢,因为直接调用了正确的JSONExport对象。
至此,疑惑的问题解决了。可以认为是调用到了垃圾数据了。
小结:
主要讲述了自己的一些体会,里面有许多不足,请大家指正~
参考资料和推荐阅读
链接: 参考资料
欢迎阅读,各位老铁,如果对你有帮助,点个赞加个关注呗!~