使用相对路径导入Spring bean定义文件

时间:2016-03-29 05:25:35

标签: java spring

我正在为JAVA中的项目编写spring配置。我是春天的新手,不能弄清楚与春天有关的错误。 我有以下文件结构:

ProjectName
--> src
    --> META-INF
        --> jobs
            -->edx
               -->request-details.xml
            -->clients.xml
            -->daos.xml
            -->environment.xml
        --> request-details-edx-upload.xml

在META-INF / request-details-edx-upload.xml中,我导入以下内容:

<import resource="jobs/environment.xml" />
<import resource="classpath:META-INF/jobs/edx/request-details.xml" />
<import resource="jobs/clients.xml" />
<import resource="jobs/daos.xml" />

但是我收到以下错误:

Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:META-INF/jobs/edx/request-details.xml]
Offending resource: class path resource [META-INF/request-details-edx-upload.xml]; nested exception is org.springframework.beans.factory.parsing.BeanDefinitionParsingException:  Configuration problem: Cannot locate BeanDefinitionDecorator for attribute [dataSetName]
Offending resource: class path resource [META-INF/jobs/edx/request-details.xml]

request-details.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"
    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/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
    ">
 <!-- RequestDetails EDX data upload dao -->
 <bean id="requestDetailsDataUploadDao" class="com.amazon.edx.dao.DataUploadDaoEdxClientImpl"
 context:providerName="scot"
 context:subjectName="${edxRequestDetailsSubject}"
 context:dataSetName="by-01-day"
 context:keyName="${regionValue}"
 context:edxClient-ref="edxClient"
 />
 <util:list id="requestDetailsColumnMetaData" value-type="com.amazon.edx.transformer.ColumnMetaData">
        <ref bean="Column"/>
        <ref bean="Column1"/>                   
 </util:list>
<bean id="Column" class="com.amazon.edx.transformer.ColumnMetaData"
    context:attributeName="Id"
    context:dataType="VARCHAR2"
    context:columnDisplayName="IMS"
/>    
<bean id="Column1" class="com.amazon.edx.transformer.ColumnMetaData"
    context:attributeName="id1"
    context:dataType="VARCHAR2"
    context:columnDisplayName="IMS"
/>
<util:constant id="tabDelimiter"
        static-field="com.amazon.edx.transformer.Delimiters.TAB_DELIMITER"    />


 <!-- RequestDetails data backup --> 
<bean id="requestDetailsDataTransformer" class="com.amazon.edx.transformer.DataTransformerImpl"
context:dataFlattener-ref="requestDetailsDataFlattener"
context:columnMetadata-ref="requestDetailsColumnMetaData"
context:delimiter="{tabDelimiter}"
/>
 </beans> 

我导入相对路径有什么明显的错误吗?

感谢。

1 个答案:

答案 0 :(得分:0)

似乎是错误的架构定义。尝试从xmlns:context="http://www.springframework.org/schema/context"标记中删除namspace <beans>。而是添加xmlns:p="http://www.springframework.org/schema/p"命名空间。此外,您应该将所有context:后缀替换为p:后缀。使用带有p命名空间的快捷方式的正确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"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/util
        http://www.springframework.org/schema/util/spring-util-3.0.xsd">

   <!-- RequestDetails EDX data upload dao -->
   <bean id="requestDetailsDataUploadDao" class="com.amazon.edx.dao.DataUploadDaoEdxClientImpl"
      p:providerName="scot"
      p:subjectName="${edxRequestDetailsSubject}"
      p:dataSetName="by-01-day"
      p:keyName="${regionValue}"
      p:edxClient-ref="edxClient"
   />

   ....

</beans>