J'ai la classe de configuration Spring suivante que j'obscurcis avec Proguard. J'ai donné les options Proguard que j'utilise ci-dessous. La classe doit être liée à une propriété nommée http.cache.timeToLiveInDays
à partir du fichier de propriétés.Liaison de propriété Spring avec Proguard
@ConfigurationProperties(prefix = "onboarding", ignoreUnknownFields = false)
public class OnboardingProperties {
private final Http http = new Http();
public Http getHttp() {
return http;
}
public static class Http {
private final Cache cache = new Cache();
public Cache getCache() {
return cache;
}
public static class Cache {
private int timeToLiveInDays = 1461;
public int getTimeToLiveInDays() {
return timeToLiveInDays;
}
public void setTimeToLiveInDays(final int timeToLiveInDays) {
this.timeToLiveInDays = timeToLiveInDays;
}
}
}
}
Le fichier de propriétés application.yml
contient les éléments suivants,
onboarding:
http:
cache:
timeToLiveInDays: 1234
configuration Proguard,
-injars ../$FINAL_NAME$/WEB-INF/lib/$FINAL_NAME$.jar
-outjars ./
-dontoptimize
# -dontshrink
# -dontusemixedcaseclassnames
# -dontpreverify
-verbose
-printseeds seeds.txt
-optimizations !class/marking/final
-adaptresourcefilenames **.properties
-adaptresourcefilecontents **.properties,META-INF/MANIFEST.MF
-keep public class com.test.blah.OnboardingApp {
public static void main(java.lang.String[]);
}
-keep public class * extends org.springframework.boot.web.support.SpringBootServletInitializer
-keep class com.test.blah**.dto.** {
void set*(***);
*** get*();
}
-keep public class com.test.blah.config.OnboardingProperties
-keep public class com.test.blah.config.OnboardingProperties$* {
*;
}
-keep class org.springframework.**
-keep class liquibase.**
-keep interface org.springframework.**
-keep interface liquibase.**
-keepclassmembers class * {
@org.springframework.beans.factory.annotation.Autowired *;
@org.springframework.beans.factory.annotation.Qualifier *;
@org.springframework.beans.factory.annotation.Value *;
@org.springframework.beans.factory.annotation.Required *;
@org.springframework.context.annotation.Bean *;
@org.springframework.context.annotation.Primary *;
@org.springframework.boot.context.properties.ConfigurationProperties *;
@javax.inject.Inject *;
@javax.annotation.PostConstruct *;
@javax.annotation.PreDestroy *;
}
-keep @org.springframework.stereotype.Service class *
-keep @org.springframework.stereotype.Controller class *
-keep @org.springframework.stereotype.Component class *
-keep @org.springframework.stereotype.Repository class *
-keep @org.springframework.context.annotation.Configuration class *
-keep @org.springframework.web.bind.annotation.ControllerAdvice class *
-keep @org.springframework.boot.context.properties.ConfigurationProperties class *
-keep @org.springframework.boot.autoconfigure.SpringBootApplication class *
-allowaccessmodification
-keepattributes Deprecated,SourceFile,LineNumberTable,LocalVariable*Table,Synthetic,EnclosingMethod
-keepattributes *Annotation*
-keepattributes Signature
-keepattributes Exceptions
-keepattributes InnerClasses
-keepparameternames
-keepdirectories
-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);
public static ** fromValue(java.lang.String);
}
-keepnames class * implements java.io.Serializable
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
!static !transient <fields>;
!private <fields>;
!private <methods>;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}
Malheureusement, je semble obtenir l'erreur suivante lorsque son essayant de se lier à la propriété .
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'http[cache][timeToLiveInDays]' of bean class [com.test.blah.config.OnboardingProperties]: Cannot access indexed value in property referenced in indexed property path 'http[cache][timeToLiveInDays]'; nested exception is org.springframework.beans.NotReadablePropertyException: Invalid property 'http[cache][timeToLiveInDays]' of bean class [com.test.blah.config.OnboardingProperties]: Bean property 'http[cache][timeToLiveInDays]' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyHoldingValue(AbstractNestablePropertyAccessor.java:405)
at org.springframework.beans.AbstractNestablePropertyAccessor.processKeyedProperty(AbstractNestablePropertyAccessor.java:298)
at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:289)
at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:280)
at org.springframework.boot.bind.RelaxedDataBinder$RelaxedBeanWrapper.setPropertyValue(RelaxedDataBinder.java:699)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:95)
at org.springframework.validation.DataBinder.applyPropertyValues(DataBinder.java:859)
at org.springframework.validation.DataBinder.doBind(DataBinder.java:755)
at org.springframework.boot.bind.RelaxedDataBinder.doBind(RelaxedDataBinder.java:128)
at org.springframework.validation.DataBinder.bind(DataBinder.java:740)
at org.springframework.boot.bind.PropertiesConfigurationFactory.doBindPropertiesToTarget(PropertiesConfigurationFactory.java:272)
at org.springframework.boot.bind.PropertiesConfigurationFactory.bindPropertiesToTarget(PropertiesConfigurationFactory.java:240)
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessBeforeInitialization(ConfigurationPropertiesBindingPostProcessor.java:329)
... 70 more
Caused by: org.springframework.beans.NotReadablePropertyException: Invalid property 'http[cache][timeToLiveInDays]' of bean class [com.test.blah.config.OnboardingProperties]: Bean property 'http[cache][timeToLiveInDays]' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyValue(AbstractNestablePropertyAccessor.java:633)
at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyHoldingValue(AbstractNestablePropertyAccessor.java:402)
... 82 more
Des idées comment je peux résoudre ce problème?