ProGuard will make Spring Bean name conflict

Startup error

2020-11-06 18:07:31.452  WARN 13120 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.maple.MapleApplication]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'a' for bean class [com.maple.a.d.a.a] conflicts with existing, non-compatible bean definition of same name and class [com.maple.a.b.a]
2020-11-06 18:07:31.463 ERROR 13120 --- [           main] o.s.boot.SpringApplication               : Application run failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.maple.MapleApplication]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'a' for bean class [com.maple.a.d.a.a] conflicts with existing, non-compatible bean definition of same name and class [com.maple.a.b.a]

I tried to use Spring definition.getBeanClassName() naming rules, but it didn’t work. Is it too much trouble if you want to manually set the name of each bean on the annotation? Can ProGuard provide the function of not repeating the class name? I haven’t found it yet.

Hello XiaoyuZhann,

The problem is that if you don’t specify the name with the components, then the name is taken from the class name. And if two components are in two different packages, they can both end up being named, for example “a”. This creates a naming conflict.

The fastest and easiest solution here, is to keep all the Component classes:

keep 'public @org.springframework.stereotype.Component class **'

This will prevent naming conflicts.

Alternatively, it is possible to specify bean names in @Component and other stereotypes (e.g. @Repository, @Service and @Controller). For example,

@Component("myBeanName")

public class MyBean {

}

Please let us know if anything is not clear.

Kind Regards,

Jack