proguard混淆后类名冲突
org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'a' for bean class [com.xxx.xxx.b.e.a] conflicts with existing, non-compatible bean definition of same name and class [com.xxx.xxx.b.d.a]
解决方法
修改启动类的main方法,在方法中自定义beanname策略,使用完整name,包含包名
public static void main(String[] args) {
new SpringApplicationBuilder(WebApplication.class).beanNameGenerator(new AnnotationBeanNameGenerator() {
@Override
protected String buildDefaultBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) {
return definition.getBeanClassName();
}
}).run(args);
}
自定义注解在proguard混淆后出现了error Type referred to is not an annotation type xxx
这种错误通常发生在使用了自定义注解,并且进行了混淆的情况下。
出现这个错误是因为在混淆过程中,ProGuard把注解的类名混淆了,导致注解丢失了。为了解决这个问题,我们需要告诉ProGuard不要混淆注解的类名。
可以通过添加如下规则到ProGuard配置文件中来避免这个错误:
-keepattributes *Annotation*
-keepclassmembers @com.example.MyAnnotation class * {
<fields>;
<methods>;
}
其中,com.example.MyAnnotation 替换成你自己注解的全限定名。
这个规则的作用是:
-keepattributes Annotation:告诉ProGuard保留注解的所有属性,即不混淆注解中的属性名。
-keepclassmembers @com.example.MyAnnotation class * { ; ;}:告诉ProGuard在混淆时不要混淆被 @com.example.MyAnnotation 注解标注的类的字段和方法。