当我用spring v.3.1执行我的java项目时,我得到以下错误:
Bean 'configParser'; nested exception is
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/util]
Offending resource: class path resource [Services.xml]
Bean 'configParser'
Run Code Online (Sandbox Code Playgroud)
我的POM具有以下依赖性:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我的Service.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd">
<bean id="configParser" class="com.cc.mp.srv.core.parser.ConfigParser">
<property name="file" >
<util:constant static-field="com.cc.mp.srv.main.Main.FILE_NAME"/>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
为什么找不到实用程序架构?我在pom文件中插入核心依赖项.版本号也是一样的.什么需要春天呢?
编辑
Loading schema mappings from [META-INF/spring.schemas]
2015-01-31 18:56:11,553 DEBUG (main) [org.springframework.beans.factory.xml.PluggableSchemaResolver] - Loaded schema mappings: {http://www.springframework.org/schema/tx/spring-tx-2.5.xsd=org/springframework/transaction/config/spring-tx-2.5.xsd, http://www.springframework.org/schema/tx/spring-tx-3.1.xsd=org/springframework/transaction/config/spring-tx-3.1.xsd, http://www.springframework.org/schema/tx/spring-tx-2.0.xsd=org/springframework/transaction/config/spring-tx-2.0.xsd, http://www.springframework.org/schema/tx/spring-tx.xsd=org/springframework/transaction/config/spring-tx-3.1.xsd, http://www.springframework.org/schema/tx/spring-tx-3.0.xsd=org/springframework/transaction/config/spring-tx-3.0.xsd}
Run Code Online (Sandbox Code Playgroud)
如果输出调试消息,则可以识别出使用了各种版本号.可能是原因?如何定义数字?
我还使用maven-assembly-plugin来创建一个可执行的jar文件.
Ral*_*lph 10
架构http://www.springframework.org/schema/util/spring-util.xsd, http://www.springframework.org/schema/util/spring-util-3.1.xsd(和一个与版本)来与spring-beans-<version>.RELEASE.jar
将此jar添加到您的依赖项:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
maven-assembly-plugin的问题:
你写了:
我还使用maven-assembly-plugin来创建一个可执行的jar文件.
啊......我猜maven-assembly-plugin是造成这个问题的原因.这是因为模式解析机制以这种方式工作:Spring提供带有jar的XSD文件.在jar中,文件夹中META-INF是一个文件schema.info.此文件包含所有XSD fiels的列表以及此jar提供的位置(在jar中).
例如:spring.schema of spring-beans-3.1.1.RELEASE.jar
http\://www.springframework.org/schema/beans/spring-beans-2.0.xsd=org/springframework/beans/factory/xml/spring-beans-2.0.xsd
http\://www.springframework.org/schema/beans/spring-beans-2.5.xsd=org/springframework/beans/factory/xml/spring-beans-2.5.xsd
http\://www.springframework.org/schema/beans/spring-beans-3.0.xsd=org/springframework/beans/factory/xml/spring-beans-3.0.xsd
http\://www.springframework.org/schema/beans/spring-beans-3.1.xsd=org/springframework/beans/factory/xml/spring-beans-3.1.xsd
http\://www.springframework.org/schema/beans/spring-beans.xsd=org/springframework/beans/factory/xml/spring-beans-3.1.xsd
http\://www.springframework.org/schema/tool/spring-tool-2.0.xsd=org/springframework/beans/factory/xml/spring-tool-2.0.xsd
http\://www.springframework.org/schema/tool/spring-tool-2.5.xsd=org/springframework/beans/factory/xml/spring-tool-2.5.xsd
http\://www.springframework.org/schema/tool/spring-tool-3.0.xsd=org/springframework/beans/factory/xml/spring-tool-3.0.xsd
http\://www.springframework.org/schema/tool/spring-tool-3.1.xsd=org/springframework/beans/factory/xml/spring-tool-3.1.xsd
http\://www.springframework.org/schema/tool/spring-tool.xsd=org/springframework/beans/factory/xml/spring-tool-3.1.xsd
http\://www.springframework.org/schema/util/spring-util-2.0.xsd=org/springframework/beans/factory/xml/spring-util-2.0.xsd
http\://www.springframework.org/schema/util/spring-util-2.5.xsd=org/springframework/beans/factory/xml/spring-util-2.5.xsd
http\://www.springframework.org/schema/util/spring-util-3.0.xsd=org/springframework/beans/factory/xml/spring-util-3.0.xsd
http\://www.springframework.org/schema/util/spring-util-3.1.xsd=org/springframework/beans/factory/xml/spring-util-3.1.xsd
http\://www.springframework.org/schema/util/spring-util.xsd=org/springframework/beans/factory/xml/spring-util-3.1.xsd
Run Code Online (Sandbox Code Playgroud)
所以,现在你有不同的罐子(spring-beans,spring-tx,spring-aop,spring-context...),所有的包含META-INF/spring.schemas文件,用不同的内容.另一方面,您使用maven-assembly-plugin在一个jar文件中聚合所有jar文件的内容.
我猜你也会对这个spring.handlers文件有这个问题.
看起来您可以配置maven-assembly-plugin合并此文件.见:这个答案的我怎么能在一个Maven组装合并的资源文件?
另一种解决方案是使用spring-boot-maven-plugin而不是maven-assembly-plugin
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>YOUR.MAIN.CLASS</mainClass>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
(或使用maven-shade-pluging)
| 归档时间: |
|
| 查看次数: |
7557 次 |
| 最近记录: |