Having difficulty processing proguard with spring

I have a web application using spring extensivley annotations, and I have my proguard configuration as follows:

-printmapping out.map -dontoptimize -keepdirectories -renamesourcefileattribute SourceFile -keepattributes Exceptions,SourceFile,LineNumberTable,*Annotation* -adaptresourcefilenames **.xsd,**.wsdl,**.xml,**.properties,**.gif,**.jpg,**.png -adaptresourcefilecontents **.xsd,**.wsdl,**.xml,**.properties,META-INF/MANIFEST.MF -dontshrink -keepclassmembernames class * { java.lang.Class class$(java.lang.String); java.lang.Class class$(java.lang.String, boolean); } -keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); } -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(); } -keep @org.springframework.transaction.annotation.Transactional class * -keep @org.springframework.stereotype.Service class * -keep @org.springframework.stereotype.Controller class * -keep @org.springframework.beans.factory.annotation.Autowired class * -keep @org.springframework.web.bind.annotation.ResponseBody class * -keep @org.springframework.web.bind.annotation.RequestMapping class * -keep @org.springframework.stereotype.Repository class * -keep @javax.annotation.Resource class * -keep @javax.persistence.Entity class * -keep @javax.persistence.Table class * -keep @javax.persistence.Id class * -keep @javax.persistence.GeneratedValue class * -keep @javax.persistence.Column class * -keep @javax.persistence.Transient class * -keep @org.springframework.ws.server.endpoint.annotation.Endpoint class * -keep @org.springframework.ws.server.endpoint.annotation.PayloadRoot class * -keep @org.springframework.ws.server.endpoint.annotation.ResponsePayload class * 

It was beautifully built without any warning. But after deploying to tomcat and opening the page in the browser, it waits and waits without any results. What could be the problem?

+3
java spring proguard
Jan 23 2018-12-12T00:
source share
2 answers

I figured out the problem:
proguard cannot process annotated classes, methods, fields specifically when they are run-time types. If you run proguard even with the -keep parameter for annotations, it will ruin the configuration files anyway, since it can only replace classes, methods and fields in resources that have a full package reference, that is, if and only if the class / field indicated as follows: my.package.level.purpose.MyClass/my.package.level.purpose.MyClass.myField .
Returning to annotations, the spring web application is filled with annotations, so it will be useless or not even confused at all (perhaps only utility classes will be confused).
Conlusion:
It makes no sense to confuse modern spring (3.xx +) web applications with any obfuscators, even commercial ones, because they all work on the byte side of the code and will not process annotations and ruin the config.

+4
Mar 22 '12 at 11:59
source share

You need to check the server log files to see what happens. If there is nothing clearly wrong, changing the logging level to DEBUG will give you more information on what Spring is doing.

FWIW, I expect the Spring-based application to give you a ton of problems if you try to confuse it. Spring DI handling and annotations are likely to be broken by the transformations that obfuscator performs in class files. For example, any place where the annotation refers to the name of another class or method will break if the obfuscator replaces the name of the class / method.

My advice would be to refuse obfuscation as a bad idea.

+2
Jan 23 '12 at 11:30
source share



All Articles