我有一个库 Common.License,我用 Proguard 混淆了它:
<plugin>
<groupId>com.pyx4me</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<configuration>
<obfuscate>true</obfuscate>
<options>
<option>-dontoptimize</option>
<option>-renamesourcefileattribute SourceFile</option>
<option>-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod</option>
<option>-keep public class * { public protected *;}</option>
<option>-keepclassmembernames class * {java.lang.Class class$(java.lang.String); java.lang.Class class$(java.lang.String, boolean);}</option>
<option>-keepclassmembernames class * {com.common.license.LicenseSessionStore licenseSessionStore; com.common.license.LicenseStore licenseStore;}</option>
<option>-keepclassmembers enum * {public static **[] values(); public static ** valueOf(java.lang.String);}</option>
<option>-keepclassmembers class * implements java.io.Serializable { static final long serialVersionUID; private static final java.io.ObjectStreamField[] serialPersistentFields; private void writeObject(java.io.ObjectOutputStream); private void readObject(java.io.ObjectInputStream); java.lang.Object writeReplace(); java.lang.Object readResolve();}</option>
</options>
<libs>
<lib>${java.home}/lib/rt.jar</lib>
<lib>${java.home}/lib/jsse.jar</lib>
</libs>
<addMavenDescriptor>false</addMavenDescriptor>
</configuration>
</plugin>
这个库有一个用 @Service 注释的 Spring bean:
@Service
public class LicenseServiceImpl implements LicenseService {
@Autowired(required = false)
LicenseSessionStore licenseSessionStore;
@Autowired(required = false)
LicenseStore licenseStore;
...
}
我在网络服务 Company.License 中使用这个库,我希望 LicenseService 自动装配:
@Component
public class BackgroundTasks {
@Autowired
ScheduledExecutorService scheduledExecutorService;
@Autowired
LicenseService licenseService;
...
}
所以 Company.License 依赖于 Common.License。如果我混淆 Common.License 则licenseService
不会自动装配BackgroundTasks
. 我可以解决这个问题的唯一方法是将 licenseService 明确定义为 bean:
@Bean(name = "licenseService", autowire = Autowire.BY_NAME)
public LicenseService getLicenseService() {
if (licenseService == null) {
licenseService = new LicenseServiceImpl();
}
return licenseService;
}
我不需要将其显式声明为这样的 bean,因为我已经注释了@Service
应该足以使 Spring 中的自动装配licenseService
神奇BackgroundTasks
地工作的类。但事实并非如此!
Proguard 专门做什么来使它不起作用?我可以在 Proguard 的配置中做些什么来使它对 Spring 更友好吗?
授予