Naming beans consistently makes your configuration easier to read and understand. Also, if you use Spring AOP, it helps a lot when applying advice to a set of beans related by name.
Not following accepted conventions can introduce inconsistent naming, especially when multiple developers work on the same project, leading to technical debt.
The spring documentation establishes a naming convention that consists of camel-cased names with a leading lowercase letter.
This rule raises an issue when a bean name defined in one of the following annotations does not adhere to the naming convention:
* `@Bean`
* `@Configuration`
* `@Controller`
* `@Component`
* `@Qualifier`
* `@Repository`
* `@Service`
== How to fix it
Change the bean's name to adhere to the naming conventions.
Names should be camel-cased and start with a lowercase letter, for example, `myBean`.
=== Code examples
==== Noncompliant code example
[source,java,diff-id=1,diff-type=noncompliant]
----
@Bean(name = "MyBean") // Noncompliant, the first letter of the name should be lowercase
public MyBean myBean() {
...
----
==== Compliant solution
[source,java,diff-id=1,diff-type=compliant]
----
@Bean(name = "myBean") // Compliant
public MyBean myBean() {
...
----
==== Noncompliant code example
[source,java,diff-id=2,diff-type=noncompliant]
----
@Service("my_service") // Noncompliant, the name should be camel-cased