【问题标题】:xslt file not able to find in classpath在类路径中找不到 xslt 文件
【发布时间】:2021-03-18 00:03:54
【问题描述】:

尝试使用包含规则的 XSLT 文件将一个 xml 转换为另一个 xml

使用 xslt 存在于 src/main/resources/test.xslt 中从输入文件夹中读取转换,并将输出存储在 F 驱动器的输出文件夹中

 @Component
  public class MyRoute extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        from("file:F:\\input")
        .to("xslt:file:///springApp/test.xslt")
        .to("file:F:\\output");
        
}

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.xml.validation</groupId>
    <artifactId>springApp</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.2</version>
        <relativePath />
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.apache.camel.springboot</groupId>
            <artifactId>camel-spring-boot-starter</artifactId>
            <version>3.7.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

    </dependencies>
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <java.version>1.8</java.version>
    </properties>
</project>

错误:-

org.apache.camel.FailedToStartRouteException: Failed to start route route1 because of null
    at org.apache.camel.impl.engine.RouteService.warmUp(RouteService.java:122) ~[camel-base-engine-3.7.0.jar:3.7.0]
    at org.apache.camel.impl.engine.InternalRouteStartupManager.doWarmUpRoutes(InternalRouteStartupManager.java:270) ~[camel-base-engine-3.7.0.jar:3.7.0]
    at org.apache.camel.impl.engine.InternalRouteStartupManager.safelyStartRouteServices(InternalRouteStartupManager.java:157) ~[camel-base-engine-3.7.0.jar:3.7.0]


Caused by: org.apache.camel.RuntimeCamelException: javax.xml.transform.TransformerException: java.io.FileNotFoundException: \\springApp\test.xslt (The network path was not found)
    at org.apache.camel.RuntimeCamelException.wrapRuntimeException(RuntimeCamelException.java:66) ~[camel-api-3.7.0.jar:3.7.0]
    at org.apache.camel.support.service.BaseService.doFail(BaseService.java:409) ~[camel-api-3.7.0.jar:3.7.0]

尝试改变路径 -

@Component
public class MyRoute extends RouteBuilder {

    @Override
    public void configure() throws Exception {
        from("file:F:\\input")
        .to("xslt:springApp/src/main/resources/test.xslt")
        .to("file:C:\\output");

}

遇到错误

org.apache.camel.FailedToCreateRouteException: Failed to create route route1 at: >>> To[xslt:springApp/src/main/resources/test.xslt] <<< in route: Route(route1)[From[file:F:\input] -> [To[xslt:springApp because of Failed to resolve endpoint: xslt://springApp/src/main/resources/test.xslt due to: javax.xml.transform.TransformerException: java.io.FileNotFoundException: Cannot find resource: classpath:springApp /src/main/resources/test.xslt in classpath for URI: classpath:springApp /src/main/resources/test.xslt
    at org.apache.camel.reifier.RouteReifier.doCreateRoute(RouteReifier.java:229) ~[camel-core-reifier-3.7.0.jar:3.7.0]

Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: xslt://springApp/src/main/resources/test.xslt due to: javax.xml.transform.TransformerException: java.io.FileNotFoundException: Cannot find resource: classpath:springApp/src/main/resources/test.xslt in classpath for URI: classpath:springApp/src/main/resources/test.xslt

        at org.apache.camel.reifier.RouteReifier.createRoute(RouteReifier.java:73) ~[camel-core-reifier-3.7.0.jar:3.7.0]

【问题讨论】:

    标签: xml spring-boot xslt apache-camel


    【解决方案1】:

    您只需要类路径中的相对路径,这将是:

    to("xslt:test.xslt")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-26
      • 1970-01-01
      • 2021-12-01
      • 1970-01-01
      • 2015-08-25
      • 1970-01-01
      • 2012-11-01
      • 1970-01-01
      相关资源
      最近更新 更多