【问题标题】:Using Proguard with a library that uses Spring @Autowired by name将 Proguard 与按名称使用 Spring @Autowired 的库一起使用
【发布时间】:2011-05-22 23:04:54
【问题描述】:

我正在使用 Proguard 来混淆具有多个 @Autowired 字段的库。混淆器正在重命名这些类字段(因为它们是类私有/内部的),因此我的 bean 无法实例化。

预混淆:

@Service
public class LicenseServiceImpl implements LicenseService {

    @Autowired(required = false)
    LicenseSessionStore licenseSessionStore;

    @Autowired(required = false)
    LicenseStore licenseStore;

...
}

后混淆:

@Service
public class LicenseServiceImpl implements LicenseService {

  @Autowired(required=false)
  LicenseSessionStore a;

  @Autowired(required=false)
  LicenseStore b;

...
}

现在可能有很多方法可以使这些特定字段不被自动装配,但我希望找到一种方法来告诉 Proguard 不要混淆任何带有重要 Spring-isms 注释的内部字段(@Autowired,等等)。

任何人都知道我一般如何做到这一点?

授予

【问题讨论】:

    标签: spring obfuscation proguard autowired


    【解决方案1】:

    我不认为这是对我的问题的正确答案,并且仍然希望有一个优雅、通用的解决方案来解决这个问题。我发布的是我的临时解决方法,它让我以最粗暴、最不优雅的方式解决了我的问题。

    我通过将这些项目添加到 keepclassmembernames 选项中明确排除了混淆:

    <option>-keepclassmembernames class * {com.common.license.LicenseSessionStore licenseSessionStore; com.common.license.LicenseStore licenseStore; }</option>
    

    这不是首选解决方案,因为它需要在每个类中进行特定的命名覆盖,并且将成为维护的噩梦。

    仍然需要更好的答案!

    授予

    【讨论】:

      【解决方案2】:

      我在为 simplexml 注释类保留类名时遇到了类似的问题。我的解决方法是添加以下内容:

      -keepclassmembers class * {
          @org.simpleframework.xml.* *;
      }
      

      我认为类似的东西对你有用:

      -keepclassmembers class * {
          @org.springframework.beans.factory.annotation.* *;
      } 
      

      【讨论】:

        猜你喜欢
        • 2010-10-30
        • 2013-11-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-02-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多