springboot项目使用proguard混淆后启动出现的几种错误

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 注解标注的类的字段和方法。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值