gpt4 book ai didi

spring - 避免在单个 jar 中合并多个 spring 依赖项时覆盖 spring.handlers/spring.schemas 的想法

转载 作者:IT老高 更新时间:2023-10-28 13:05:26 28 4
gpt4 key购买 nike

我收到错误 Unable to Location NamespaceHandler when using context:annotation-config running (java -jar) 由 maven-assembly-plugin 组装并包含我的项目及其所有依赖项的 jar。

正如其他人在 forum.springsource.org thread (message #7/8) 上正确发现的那样出现问题是因为存在于不同 jar 中的文件 META-INF/spring.handlersMETA-INF/spring.schemas 在 maven-assembly- 时被覆盖插件将 jar 重新打包到一个文件中。

查看两个 spring-*.jar 文件的内容,您可以看到这些文件相对于类路径位于相同的位置

$ jar tf spring-oxm-3.0.3.RELEASE.jar
META-INF/spring.handlers
META-INF/spring.schemas
org/springframework/oxm/GenericMarshaller.class
...

$ jar tf spring-context-3.0.3.RELEASE.jar
META-INF/spring.handlers
META-INF/spring.schemas
org/springframework/context/ApplicationContext.class

不可以把 META-INF 文件夹放在特定的包里吗?如果是这样,我建议的想法(希望它适用)是将 META-INF/spring.shemasMETA-INF/spring.handlers 文件放在他们引用的包。

$ jar tf spring-oxm-3.0.3.RELEASE.jar
org/springframework/oxm/META-INF/spring.schemas
org/springframework/oxm/META-INF/spring.handlers
org/springframework/oxm/GenericMarshaller.class
...

$ jar tf spring-context-3.0.3.RELEASE.jar
org/springframework/context/META-INF/spring.handlers
org/springframework/context/META-INF/spring.schemas
org/springframework/context/ApplicationContext.class

这样它们在合并到一个 jar 中时不会发生冲突。你怎么看?

最佳答案

我设法使用着色器插件而不是(错误的)汇编器插件来消除错误:

        <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>at.seresunit.lecturemanager_connector.App</mainClass>
</transformer>
<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>
</configuration>
</execution>
</executions>
</plugin>

我想我在 springsource 论坛上找到了解决方案.. 自从我查到它已经有一段时间了.. 不记得作者了。无论如何都要向他致敬:p

干杯

关于spring - 避免在单个 jar 中合并多个 spring 依赖项时覆盖 spring.handlers/spring.schemas 的想法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5586515/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com