开发者

Using Proguard with a library that uses Spring @Autowired by name

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


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.* *;
} 


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜