spring-data-jpa - 阴影 jar 无法找到 XML 模式命名空间的 Spring NamespaceHandler [http://www.springframework.org/schema/data/jpa]
问题描述
当我使用 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 中的一个文件中。享受 :-)
推荐阅读
- python - Python 中的累积持续时间构建
- c - 在 K&R C 中传递字符串文字
- google-app-engine - Google Cloud Endpoints 和 Guice 出现错误“调用者没有权限”
- requirejs - RequireJS 转译插件应该如何返回结果?
- javascript - 如何根据他们的选择(使用 Mailchimp)将潜在客户发送到特定的邮件列表?
- python - Matplotlib:向散点图添加颜色图例
- python - 如何使用 PyPDF2 在 Python 3 中将 PDF 中的所有页面作为单个字符串检索
- node.js - forEach 不在 lambda 函数内运行
- java - Kafka Connect 无法将自定义存储接收器分区器转换为分区器接口
- java - 找不到接口类型的 Bean