Standard naming to the Spring beans

孤街醉人 提交于 2019-12-03 11:40:56

Bean Naming Conventions (Spring Manual section 3.3.1)

The convention is to use the standard Java convention for instance field names when naming beans. That is, bean names start with a lowercase letter, and are camel-cased from then on. Examples of such names would be (without quotes) 'accountManager', 'accountService', 'userDao', 'loginController', and so forth.

Naming beans consistently makes your configuration easier to read and understand, and if you are using Spring AOP it helps a lot when applying advice to a set of beans related by name.

camelCase seems right! For bean Id's, the naming convention would be same as Java class field name. The bean ID for an instance of ServiceDAO would be serviceDAO. The package name can be prefixed to the bean ID for larger projects.

Are you not using annotations? If you do then you don't need to follow any bean id naming convention.

If not (for whatever strange reasons) then camelCase is right. But the naming convention has to indicate which layer the bean belongs and ofcourse the name should correspond to the class its going to be injecting.

Hope that helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!