2017-04-15 84 views
1

我正在開發一個項目(spring boot),我必須使用maven jaxb2插件將xml文件轉換爲Java類。我正在關注這個鏈接: 這些類生成的問題是,當我嘗試解開xml我有這個錯誤: 資源ServletContext資源[/ xsd/MX_seev_031_001_05。 XSD]不存在 這是我的application.properties:資源ServletContext資源不存在

context.path =xml.swift.spring.com 
schema.location= xsd/MX_seev_031_001_05.xsd 

配置的本我的豆:

XSD文件是在src /主/資源/ XSD,這是我的聚甲醛.XML:

<plugin> 
<groupId>org.jvnet.jaxb2.maven2</groupId> 
<artifactId>maven-jaxb2-plugin</artifactId> 
<version>0.12.1</version> 
<executions> 
    <execution> 
     <id>add-source-for-demoapp</id> 
     <goals> 
      <goal>generate</goal> 
     </goals> 
     <configuration> 
      <schemaDirectory>${project.basedir}/src/main/resources/xsd</schemaDirectory> 
      <schemaIncludes> 
       <include>*.xsd</include> 
      </schemaIncludes> 


      <!-- Other configuration options--> 

     </configuration> 
    </execution> 
</executions> 

缺什麼我'?

謝謝。

回答

0

我基本上有同樣的問題,當我開始在我的pom.xml中使用spring-boot-starter-data-rest以及spring-oxm(我也有spring-boot-starter-data-jpa)時。

問題在於你的第二個自動注入的參數; @Value( 「$ {} schema.location」)最終資源schemaResource

所以不是

@Bean 
public Jaxb2Marshaller createJaxb2Marshaller(@Value("${context.path}") final String contextPath, @Value("${schema.location}") final Resource schemaResource){ 
    //... 
    marshaller.setSchema(schemaResource); 
    //... 
} 

下面做;

@Bean 
public Jaxb2Marshaller createJaxb2Marshaller(@Value("${context.path}") final String contextPath, @Value("${schema.location}") final String schemaLocation){ 
    //... 
    Resource schemaResource = new ClassPathResource(schemaLocation); 
    marshaller.setSchema(schemaResource); 
    //... 
} 

試試看,它會起作用。