When the bean class name is duplicated

Even if the compilation passes, an error will occur at runtime, so you must give a unique name. If you attach them one by one by hand, mistakes are likely to occur, so attach them automatically.

Define a naming class directly under the root path, etc.

FQCNBeanNameGenerator.java


public class FQCNBeanNameGenerator extends AnnotationBeanNameGenerator {

    @Override
    protected String buildDefaultBeanName(BeanDefinition definition) {
        return definition.getBeanClassName();
    }
}

Changed servlet-context.xml

Before change: servlet-context.xml


	<context:component-scan base-package="jp.co.test" />

After change: servlet-context.xml


	<context:component-scan
		base-package="jp.co.test"
		 name-generator="jp.co.test.FQCNBeanNameGenerator" />

reference

https://qiita.com/sinsengumi/items/655d9f3ff49646dfe61a http://d.hatena.ne.jp/ocs/20101129/1291034951

Recommended Posts

When the bean class name is duplicated
When you get lost in the class name
The migration file is duplicated
What is the BufferedReader class?
ActiveModel is convenient when creating Form class
Error when the member of Entity class used in SpringWebFlux is final
Be careful when setting the class name when creating a document-based app in Swift
Customize the bean name set by Spring component-scan
[Java] Where is the implementation class of annotation that exists in Bean Validation?
The official name of Spring MVC is Spring Web MVC
When the project is not displayed in eclipse
ClassLoader cannot scan the desired class only when a specific maven task is executed
How to get the class name of the argument of LoggerFactory.getLogger when using SLF4J in Java
When the hover of Eclipse is hard to see
What is the difference between a class and a struct? ?? ??
Get the name of the test case in the JUnit test class
When the month of the date is acquired, the January shift
About Class loading and initialization when the JVM starts
[Swift] Setting the behavior when the Share button is pressed
Why the get method is needed in the Calendar class
About the StringBuilder class
[Rails] Record when the event did not fire when the javascript file name is the same as the controller
wsimport error handling (A class / interface with the same name "xxx" is already in use)
How to get the class name / method name running in Java
When is the default value automatically entered without explicit initialization?
What is the LocalDateTime class? [Java beginner] -Date and time class-
When using the constructor of Java's Date class, the date advances by 1900.
The idea of cutting off when the error is not resolved
% rails db: When creating, the LoadError caused by mimemagic is
[Rails] When the layout change of devise is not reflected
I want to give a class name to the select attribute
Behavior when each is executed in the reverse order Range
[Swift] Get the timing when the value of textField is changed
Logback log is not output when the server application is closed