Standard naming to the Spring beans

2019-03-24 19:34发布

Somebody knows an standard naming to the Spring beans in a App Context?

I used the camel case naming, but I'm not sure if exists an kind of standard, I searched in the net about that but I haven't found something.

3条回答
Rolldiameter
2楼-- · 2019-03-24 20:01

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.

查看更多
可以哭但决不认输i
3楼-- · 2019-03-24 20:18

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.

查看更多
Anthone
4楼-- · 2019-03-24 20:19

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.

查看更多
登录 后发表回答