gpt4 book ai didi

java - Maven 阴影无法找到 XML 模式命名空间的 Spring NamespaceHandler

转载 作者:行者123 更新时间:2023-11-30 09:34:03 28 4
gpt4 key购买 nike

我有一个小的 Spring 项目,我用 roo 1.2.2 启动

我可以在 Eclipse Juno 中很好地运行主类。但是,当我尝试运行使用 mvn package 构建的 JAR 文件时,我收到以下错误:

Exception in thread "main" 
org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem: Unable to locate Spring NamespaceHandler for
XML schema namespace [http://www.springframework.org/schema/tx]
Offending resource: class path resource [META-INF/spring/applicationContext.xml]

我正在使用 Maven shade 插件构建 uber JAR,配置如下:

<build>
<pluginManagement>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.7.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.xyz.watcher.WatcherMain</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
...

在 pom.xml 属性中我有 <spring.version>3.1.2.RELEASE</spring.version>其中一个依赖项是:

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>

应用上下文头部如下:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">

在我的主程序中我有:

String[] springConf = new String[] { "META-INF/spring/applicationContext.xml",
"META-INF/spring/watcher.xml" };
BeanFactory appContext = new ClassPathXmlApplicationContext(springConf);

当我输入 mvn package 时我明白了

[INFO] Building jar: /home/stivlo/workspace/monitor/target/monitor-0.1.0.BUILD-SNAPSHOT.jar
[INFO] --- maven-shade-plugin:1.7.1:shade (default) @ monitor ---
...
[INFO] Including org.springframework:spring-tx:jar:3.1.2.RELEASE in the shaded JAR.

任何人都可以建议我缺少什么以及如何修复我的构建以便我可以运行我的 JAR?

最佳答案

尝试在您的配置中添加一个AppendingTransformer。 Maven 文档中的示例特别提到这对 Spring 处理程序很有用。

<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<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>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>

希望这对您有所帮助。

关于java - Maven 阴影无法找到 XML 模式命名空间的 Spring NamespaceHandler,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11938589/

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