Java Spring Boot ProGuard嵌入式Tomcat模糊处理
我不确定ProGuard是否适合这个。 我有一个Spring Boot应用程序,需要对其进行模糊处理。使用proguard maven插件,我的代码变得模糊不清。无论如何,我不得不重新打包一些JAR,因为SpringLoader不支持压缩的JAR,但这不是问题所在。 嵌入式tomcat的启动方式有问题,因为我遇到了以下问题:Java Spring Boot ProGuard嵌入式Tomcat模糊处理,java,spring,maven,tomcat,obfuscation,Java,Spring,Maven,Tomcat,Obfuscation,我不确定ProGuard是否适合这个。 我有一个Spring Boot应用程序,需要对其进行模糊处理。使用proguard maven插件,我的代码变得模糊不清。无论如何,我不得不重新打包一些JAR,因为SpringLoader不支持压缩的JAR,但这不是问题所在。 嵌入式tomcat的启动方式有问题,因为我遇到了以下问题: [main] ERROR o.s.boot.SpringApplication - Application startup failed
[main] ERROR o.s.boot.SpringApplication - Application startup failed
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springfram
ework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContaine
rFactory bean.
proguard maven插件配置
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.foogroup</groupId>
<artifactId>foo</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<name>fooname</name>
<description>foo description</description>
<groupId>foogid</groupId>
<artifactId>fooaid</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<!-- Specify Java Compiler Version -->
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>1.8.11</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.3</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<configuration>
<obfuscate>true</obfuscate>
<injar>${project.build.finalName}.jar</injar>
<outjar>${project.build.finalName}-small.jar</outjar>
<outputDirectory>${project.build.directory}</outputDirectory>
<options>
<option>-optimizations !class/marking/final</option>
<option>-adaptresourcefilecontents
**.properties,META-INF/MANIFEST.MF,META-INF/spring.*</option>
<option>-keepattributes
Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod</option>
<option>-keepclasseswithmembers public class * { public static
void main(java.lang.String[]);}</option>
<option>-keepclassmembers class * {
@org.springframework.beans.factory.annotation.Autowired *;
@org.springframework.beans.factory.annotation.Value *;
}
</option>
<option>-keep public class org.foo.**</option>
<option>-keep public class org.springframework.**</option>
</options>
<libs>
<lib>${java.home}/lib/rt.jar</lib>
</libs>
<injarNotExistsSkip>true</injarNotExistsSkip>
</configuration>
<dependencies>
<dependency>
<groupId>net.sf.proguard</groupId>
<artifactId>proguard-base</artifactId>
<version>5.2.1</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
4.0.0
org.foogroup
但是没有提到任何关于嵌入式servlet容器的问题
我怀疑我在这个过程中做错了什么,我在网上找不到关于这个具体问题的任何可靠的工作样本/提示
如果你们对如何解决这个问题有什么建议,我都听说了:)我也遇到了同样的问题
事实上,这个问题不是由“嵌入式servlet容器”引起的。我认为这是因为Proguard在spring boot重新打包之前混淆了一些类或接口。但是spring引导信息中的类/接口信息(如名称或路径)并没有相应地修改。因此,spring boot无法初始化bean,无法启动应用程序
我只需将“-keepattributes xxx”添加到proguard.conf文件中,就解决了这个问题
因为您的配置中已经有“-keepattributes”。我建议您通过使用“-keep class!”来缩小受保护文件的范围!xxx',它可能会帮助您找出导致问题的人
我的程序配置:
-target 1.8
-dontshrink
-dontoptimize
-dontnote
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,*Annotation*,EnclosingMethod
-keep class !com.hbyuan27.demo.service.DemoService { *; }
#-keep class !com.hbyuan27.demo.**.service.** { *; }
尝试更改插件的顺序,因此首先给出proguard插件,然后是带重新打包的spring boot maven插件。对我来说,这很好。你找到解决方案了吗?我现在遇到了与spring boot、gradle和proguard相同的问题。你有没有找到解决办法?