当我使用maven-shaded-plugin将所有依赖项(包括spring-data-jpa.jar)打包到一个jar中并放在WEB-INF / lib目录下时,我在Tomcat中运行的Web应用程序中遇到异常。
如果我将spring-data-jpa.jar与我的阴影jar一起直接打包到WEB-INF / lib中,问题就会消失?
NOTE: I will be running the same package as AWS Lambda hence I need to create a shaded jar.
为了帮助其他人,问题是多个spring - * .jar文件META-INF/spring.handlers
文件在运行maven-shade-plugin
时相互覆盖。
要解决在插件配置中使用<transformers>
的问题。我的最终插件配置如下所示;
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<!-- Remove signatures from transitive dependencies and append spring handlers and schemas -->
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
上面将把所有处理程序合并到最终jar中的一个文件中。请享用 :-)