Description

Enable a way to dynamically set Spring bean names for the projects in which they are defined.

Use Case

When using a Spring library within a Spring application, collisions may occur if beans share the same name. In our organization, we adhere to a template when creating Spring projects, and these templates contain standard beans. When creating a library and an application that uses that library, it causes an error since two beans have the same name.

We are aware that this can be done manually for each project, but we would like a more dynamic solution.

Proposed Behavior

We propose a feature where the bean names can be, for example, prefixed with the project name.

Example: In the template, there would be a bean defined like this:

  • @Configuration(${project}Config)

Then, in the application and library, the bean names would be like this:

  • springAppConfig
  • springLibConfig

Comment From: snicoll

Are you aware of BeanNameGenerator? If not, please give that a try and let us know how it goes.

Comment From: lfvJonas

I was not aware BeanNameGenerator, and FullyQualifiedAnnotationBeanNameGenerator solves our problem. Thank you!