无法定位 Spring NamespaceHandler 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15110671/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
unable to locate Spring NamespaceHandler error
提问by Sagarmichael
I have been having this error for nearly a week now and im just about ready to give in. I have used Maven2 to make the BIG jar file. When I run the jar file using:
我已经遇到这个错误将近一个星期了,我正准备屈服。我已经使用 Maven2 制作了 BIG jar 文件。当我使用以下命令运行 jar 文件时:
java -jar someJar.jar
I get this error:
我收到此错误:
ERROR: [27/55/13 10:55] Launcher: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/context]
Offending resource: class path resource [JavaProjectApplicationContext.xml]
JavaProjectApplicationContext.xml is as follows:
JavaProjectApplicationContext.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:jee="http://www.springframework.org/schema/jee"
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/jee
http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">
<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location"><value>deployment.properties</value></property>
</bean>
<bean id="LexEditorDataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"><value>${hibernate.jdbc_driver}</value></property>
<property name="username"><value>${hibernate.username}</value></property>
<property name="password"><value>${hibernate.password}</value></property>
<property name="url"><value>${hibernate.url}</value></property>
<property name="defaultAutoCommit"><value>${hibernate.default_auto_commit}</value> </property>
<property name="maxActive"><value>20</value></property>
<property name="maxIdle"><value>3</value></property>
<property name="testOnBorrow"><value>true</value></property>
<property name="testOnReturn"><value>true</value></property>
<property name="testWhileIdle"><value>true</value></property>
</bean>
<context:component-scan base-package="com.k_int.bank.plugin">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Service"/>
</context:component-scan>
<bean id="ThesSessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource"><ref local="LexEditorDataSource"/></property>
<property name="configurationClass"> <value>org.hibernate.cfg.AnnotationConfiguration</value></property>
<property name="packagesToScan">
<list>
<value>com.bank.kernel.datamodel</value>
</list>
</property>
<property name="annotatedClasses">
<list>
<!-- identity service -->
<value>com.svc.identity.datamodel.PartyHDO</value>
<value>com.svc.identity.datamodel.RegisteredUserHDO</value>
<value>com.svc.identity.datamodel.AuthenticationDetailsHDO</value>
<value>com.svc.identity.datamodel.GrantHDO</value>
<value>com.svc.identity.datamodel.PermissionHDO</value>
<value>com.svc.identity.datamodel.RegisteredOrganisationHDO</value>
<value>com.svc.identity.datamodel.RoleHDO</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.show_sql">false</prop>
</props>
</property>
</bean>
<bean id="IndexService" class="com.k_int.bank.index.solr_impl.SOLRIndexService" init-method="init">
<property name="indexDirectory"><value>${com.bank.index_dir}</value></property>
<property name="indexPropertyFile"><value>solr.properties</value></property>
</bean>
Things I have tried so far.
到目前为止我尝试过的事情。
built the project in 3 different ways (2 IDE's and command line) removed any jar dependancy clashes (I had spring-2.5.6.jar and spring-context-3.0.5.RELEASE.jar, So i removed spring-2.5.6.jar)
以 3 种不同方式(2 个 IDE 和命令行)构建项目删除了任何 jar 依赖冲突(我有 spring-2.5.6.jar 和 spring-context-3.0.5.RELEASE.jar,所以我删除了 spring-2.5.6 。罐)
changed http://www.springframework.org/schema/beans/spring-beans-2.5.xsdto http://www.springframework.org/schema/beans/spring-beans-3.0.xsd.
将http://www.springframework.org/schema/beans/spring-beans-2.5.xsd更改 为 http://www.springframework.org/schema/beans/spring-beans-3.0.xsd。
None of these changes have removed the error.
这些更改均未消除错误。
In the car file exists in
在汽车文件中存在
someJar.jar/org/springframework/context/config/ContextNameSpaceHandler.class
Has anyone got any ideas at all.
有没有人有任何想法。
回答by Biju Kunjummen
Very likely what has happened is the files which provides meta data to Spring about the location of the custom namespace handlers(spring.schema, spring.handlers) have ended up overwriting each other when you created the big(uber) jar.
很可能发生的情况是,当您创建 big(uber) jar 时,向 Spring 提供有关自定义命名空间处理程序(spring.schema、spring.handlers)位置的元数据的文件最终相互覆盖。
To clarify this a little more, if you are using context name space say - context:property-placeholder-configurer, the information about how to parse this namespace is using a spring.handlers file in spring-context.jar!:/META-INF/spring.handlersfile, a similar file is present in other spring jar files for other custom namespaces support. Now, when you create the Uber jar, since the location of the handler file is exactly the same, one spring.handler file will end up overwriting the others, and you see the error that you are seeing. Some potential fixes are described here, where some alternate ways of creating the executable jar is suggested:
为了进一步澄清这一点,如果您使用上下文命名空间说 - context:property-placeholder-configurer,有关如何解析此命名空间的信息是使用文件中的 spring.handlers 文件spring-context.jar!:/META-INF/spring.handlers,其他 spring jar 文件中存在类似的文件以用于其他自定义命名空间支持. 现在,当您创建 Uber jar 时,由于处理程序文件的位置完全相同,因此一个 spring.handler 文件最终会覆盖其他文件,并且您会看到您所看到的错误。这里描述了一些潜在的修复,其中建议了一些创建可执行 jar 的替代方法:

