针对“无法找到SpringNamespaceHandler”错误和spring找不到或无法加载主类这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展java–Spring配置:无法找到Spri
针对“无法找到Spring NamespaceHandler”错误和spring 找不到或无法加载主类这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展java – Spring配置:无法找到Spring NamespaceHandler、java – 无法在终端中找到XML架构名称空间错误的Spring NamespaceHandler、java – 无法找到JAX-WS的Spring Namespace、java – 无法找到Spring NamespaceHandler util等相关知识,希望可以帮助到你。
本文目录一览:- “无法找到Spring NamespaceHandler”错误(spring 找不到或无法加载主类)
- java – Spring配置:无法找到Spring NamespaceHandler
- java – 无法在终端中找到XML架构名称空间错误的Spring NamespaceHandler
- java – 无法找到JAX-WS的Spring Namespace
- java – 无法找到Spring NamespaceHandler util
“无法找到Spring NamespaceHandler”错误(spring 找不到或无法加载主类)
我正在用Spring创建一个独立的Sava应用程序,以处理JDBC访问。该应用程序在每次测试中都可以正常运行,因此我决定需要一个jar来部署我们的客户。
他们的类路径中可能没有spring,因此我使用maven-assembly-plugin处理具有依赖项的jar创建。
但是,当我尝试运行该应用程序时:
java -jar target/myproject-0.0.1-SNAPSHOT-jar-with-dependencies.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/p]Offending resource: class path resource [applicationContext.xml]at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:80)...and so on to the database access class of this project.
applicationContext.xml文件位于projectbase / src / main /
resources中。并将其放置在目标/程序包名称库中。
applicationContext.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:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <bean id="dataSourceDesenv"... /> <bean id="simpleJdbcDaoSupport"p:dataSource-ref="dataSourceDesenv" /> <bean id="simpleJdbcTemplate"> <constructor-arg ref="dataSourceDesenv" /> </bean></beans>
答案1
小编典典我发现了错误,该错误在于maven-
assembly插件中的一个未修复的错误。我使用以下解决方法:
首先注释掉pom中的maven-assembly代码。然后,我使用maben-dependency-plugin将依赖项复制到目标的lib文件夹中:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/lib</outputDirectory> </configuration> </execution> </executions></plugin>
然后,我使用maven-jar-plugin设置了我的可执行jar:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.3.1</version> <configuration> <archive> <index>true</index> <manifest> <addClasspath>true</addClasspath> <mainClass>org.foo.myproject.App</mainClass> </manifest> <manifestEntries> <mode>development</mode> <url>${pom.url}</url> <key>value</key> </manifestEntries> </archive> </configuration> </plugin>
最后,我创建了一个bash脚本,该脚本与该应用程序一起部署,该应用程序使用其libs和任何提供的参数来运行我的应用程序:
java -cp lib/*:myproject-0.0.1-SNAPSHOT.jar org.foo.myproject.App $@
我应该在python = /中构建该应用程序
java – Spring配置:无法找到Spring NamespaceHandler
解决方法
apply plugin: 'java' apply plugin: 'idea' apply plugin: 'com.github.johnrengelman.shadow' apply plugin: 'application' mainClassName = 'ru.antowka.Initializer' buildscript { repositories { jcenter() } dependencies { classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.2' } } jar { manifest { attributes 'Main-Class': mainClassName } } shadowJar { mergeServiceFiles('meta-inf/spring.*') } // JDK 8 sourceCompatibility = 1.8 targetCompatibility = 1.8 compileJava.options.encoding = 'UTF-8' repositories { maven { url 'http://repo.spring.io/snapshot' } mavenLocal() mavenCentral() jcenter() } dependencies { compile 'org.jsoup:jsoup:1.8.3' compile 'org.springframework:spring-context:4.2.2.BUILD-SNAPSHOT' compile 'log4j:log4j:1.2.17' compile 'org.quartz-scheduler:quartz:1.8.6' compile 'org.springframework:spring-support:2.0.8' compile 'org.springframework:spring-tx:2.5.4' compile 'org.springframework:spring-orm:4.1.7.RELEASE' compile 'org.hibernate:hibernate-core:4.3.10.Final' compile 'org.postgresql:postgresql:9.4-1201-jdbc41' compile 'org.apache.commons:commons-dbcp2:2.1' testCompile 'org.springframework:spring-test:4.2.0.RELEASE' testCompile 'org.mockito:mockito-core:1.+' testCompile 'junit:junit:4.12' }
java – 无法在终端中找到XML架构名称空间错误的Spring NamespaceHandler
线程“main”中的异常java.lang.RuntimeException:org.springframework.beans.factory.parsing.BeanDeFinitionParsingException:配置问题:无法找到XML架构命名空间的Spring NamespaceHandler [http://cxf.apache.org/core]
违规资源:类路径资源[meta-inf / test.xml]
我的test.xml文件是
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cxf="http://cxf.apache.org/core" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd"> <bean id="clientI"/> <bean id="clientL"/> <cxf:bus> <cxf:outInterceptors> <ref bean="clientI" /> </cxf:outInterceptors> <cxf:inInterceptors> <ref bean="clientL" /> </cxf:inInterceptors> </cxf:bus> </beans>
但是相同的代码在eclipse中有效.有谁知道问题可能是什么?
解决方法
你可以从这里得到它:http://mvnrepository.com/artifact/org.apache.cxf/cxf-bundle/2.7.6(最新版本).
java – 无法找到JAX-WS的Spring Namespace
http://jax-ws-commons.java.net/spring/
我采用它并将其集成到我的applicationContext.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:context="http://www.springframework.org/schema/context" xmlns:task="http://www.springframework.org/schema/task" xmlns:ws="http://jax-ws.dev.java.net/spring/core" xmlns:wss="http://jax-ws.dev.java.net/spring/servlet" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd http://jax-ws.dev.java.net/spring/core http://jax-ws.dev.java.net/spring/core.xsd http://jax-ws.dev.java.net/spring/servlet http://jax-ws.dev.java.net/spring/servlet.xsd"> <context:annotation-config /> <context:component-scan base-package="cloud" /> <task:annotation-driven/> <wss:binding url="/notification" service="#notificationService"></wss:binding> <ws:service id="notificationService" bean="#notificationImpl"></ws:service> <bean id="notificationImpl"/> </beans>
但每次启动Tomcat时,我都会遇到以下异常:
SEVERE: Exception sending context initialized event to listener instance of class
org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.parsing.BeanDeFinitionParsingException
: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://jax-ws.dev.java.net/spring/servlet
]
Offending resource: ServletContext resource [/WEB-INF/applicationContext.xml
]
Eclipse不会报告有关命名空间的任何错误.我发现谷歌有一些类似的问题,但没有修复我的错误.
谢谢你的帮助!
解决方法
java – 无法找到Spring NamespaceHandler util
当我用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'
我的POM具有以下依赖性:
我的Service.xml文件:
为什么找不到实用程序架构?我在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}
如果输出调试消息,则可以识别出使用了各种版本号.可能是原因?如何定义数字?
我还使用maven-assembly-plugin来创建一个可执行的jar文件.
最佳答案
Schema 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添加到您的依赖项:
maven-assembly-plugin的问题:
你写了:
I also use the maven-assembly-plugin to create a executable jar file.
啊……我猜maven-assembly-plugin是造成这个问题的原因.这是因为模式解析机制以这种方式工作:Spring提供带有jar的XSD文件.在jar中,文件夹META-INF是一个文件schema.info.此文件包含所有XSD fiels的列表以及此jar提供的位置(在jar中).
例如:spring.sug 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
所以现在你有不同的jar(spring-bean,spring-tx,spring-aop,spring-context …),它们都包含一个META-INF / spring.schemas文件,内容不同.另一方面,您使用maven-assembly-plugin在一个jar文件中聚合所有jar文件的内容.
我猜你也会遇到spring.handlers文件的这个问题.
看起来您可以配置maven-assembly-plugin来合并这些文件.见:this answer的this answer
另一种解决方案是使用spring-boot-maven-plugin而不是maven-assembly-plugin
figuration>
figuration>
(或使用maven-shade-pluging)
关于“无法找到Spring NamespaceHandler”错误和spring 找不到或无法加载主类的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于java – Spring配置:无法找到Spring NamespaceHandler、java – 无法在终端中找到XML架构名称空间错误的Spring NamespaceHandler、java – 无法找到JAX-WS的Spring Namespace、java – 无法找到Spring NamespaceHandler util等相关知识的信息别忘了在本站进行查找喔。
本文标签: