2013-02-27 90 views
17

我一直有這個錯誤近一個星期了,我即將準備投入。 我已經使用Maven2來製作BIG jar文件。當我運行使用的jar文件:無法找到Spring NamespaceHandler錯誤

java -jar someJar.jar 

我得到這個錯誤:

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如下:

<?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> 



事情我至今嘗試過。

以3種不同方式構建項目(2個IDE和命令行) 刪除了任何jar依賴衝突(我有spring-2.5.6.jar和spring-context-3.0.5.RELEASE.jar,所以我刪除了spring-2.5.6.jar)

變爲http://www.springframework.org/schema/beans/spring-beans-2.5.xsd變爲http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

這些更改都沒有消除錯誤。

在車上文件存在於

someJar.jar/org/springframework/context/config/ContextNameSpaceHandler.class 

有沒有人有任何想法都沒有。

+0

更改了'beans'命名空間URI,但錯誤信息是關於'context'命名空間。嘗試從映射的URI(比如'http:// www.springframework.org/schema/context/spring-context.xsd')中刪除版本信息,這些信息應該被解析爲您的spring-context中最新版本的.xsd。罐。 – zagyi 2013-02-27 11:27:45

+0

對不起,我確實改變了春天背景。我試過你所說的還沒有運氣。 – Sagarmichael 2013-02-27 12:06:45

回答

22

很可能發生了什麼是向Spring提供元數據的文件,當您創建大(超級)的jar包時,自定義命名空間處理程序(spring.schema,spring.handlers)的位置最終會相互覆蓋。如果您使用上下文名稱空間say - context:property-placeholder-configurer,有關如何分析此名稱空間的信息使用spring-context.jar!:/META-INF/spring.handlers文件中的spring.handlers文件,則其他彈簧罐中會出現類似的文件支持其他自定義名稱空間的文件。現在,當您創建Uber jar時,由於處理程序文件的位置完全相同,因此一個spring.handler文件將最終覆蓋其他文件,並且您會看到您所看到的錯誤。一些潛在的修正在這裏所描述的,在那裏創建可執行的JAR文件的一些替代方法建議:

How to create spring-based executable jar with maven?

相關問題