将 Proguard 与按名称使用 Spring @Autowired 的库一起使用

发布于 2024-10-07 11:07:12 字数 707 浏览 7 评论 0原文

我正在使用 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 注释的内部字段 -主义(@Autowired 等)。

有人知道我一般可以如何做到这一点吗?

授予

I'm using Proguard to obfuscate a library that has several @Autowired fields. The obfuscator is renaming those class fields (because they are private/internal to the class) and thus my bean is failing to instantiate.

Pre-obfuscated:

@Service
public class LicenseServiceImpl implements LicenseService {

    @Autowired(required = false)
    LicenseSessionStore licenseSessionStore;

    @Autowired(required = false)
    LicenseStore licenseStore;

...
}

Post-obfuscation:

@Service
public class LicenseServiceImpl implements LicenseService {

  @Autowired(required=false)
  LicenseSessionStore a;

  @Autowired(required=false)
  LicenseStore b;

...
}

Now there are likely a lot of ways to make these particular fields not get autowired but what I was hoping to find was a way to tell Proguard to not obfuscate any internal fields that are annotated with important Spring-isms (@Autowired, etc.).

Anyone have an idea on how I can generically do this?

Grant

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

莫言歌 2024-10-14 11:07:12

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

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

我认为类似的内容对您有用:

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

I had a similar problem retaining class names for simplexml annotated classes. My fix was to add the following:

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

I think something similar would work for you:

-keepclassmembers class * {
    @org.springframework.beans.factory.annotation.* *;
} 
请别遗忘我 2024-10-14 11:07:12

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

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

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

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

仍然需要更好的答案!

授予

I do not consider this a correct answer to my question and would still like an elegant, generic solution to this problem. What I'm posting is my temporary workaround which got me past my issue in the most brute force, inelegant way.

I explicitly excluded these items from obfuscation by adding them into a keepclassmembernames option:

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

This is not a preferred solution as it requires specific named overriding in each and every class and will become a maintenance nightmare.

A better answer is still needed!

Grant

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文