"Mark Invalid" 从 application.properties 文件读取值时出错

"Mark Invalid" error when reading values from application.properties file

我正在学习使用带 Spring 引导的 Apache Camel。我正在做一个演示,我从 FTP 位置拾取文件并将其放到另一个位置。

当我在 from() 方法中直接使用 ftps uri 时,该路由有效。但是,当我尝试将 ftps 位置存储在 application.properties 文件中并从那里访问它时,我收到 Mark Invalid 错误。

有效:

@Override
    public void configure() throws Exception {
        fromFile();
    }
    public void fromFTP() {
        from("ftps:username@localhost/pickup?password=xxxx&delete=true")
            .to("file:E:/output");
    }

这不是:

application.properties 文件

ftps.pickup.location=ftps:username@localhost/pickup?password=xxxx

骆驼路线

  @Override
        public void configure() throws Exception {
            fromFile();
        }
        public void fromFTP() {
            from("{{ftps.pickup.location}}&delete=true")
                .to("file:E:/output");
        }

这是我收到的错误:

C:\Users\pathaks\eclipse-workspace\camel-spring-demo>mvn clean install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building camel-spring-demo 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.6.1:clean (default-clean) @ camel-spring-demo --
-
[INFO] Deleting C:\Users\pathaks\eclipse-workspace\camel-spring-demo\target
[INFO]
[INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ camel-spri
ng-demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.996 s
[INFO] Finished at: 2018-11-17T17:56:48Z
[INFO] Final Memory: 22M/123M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2
.7:resources (default-resources) on project camel-spring-demo: Mark invalid -> [
Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionE
xception

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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.pathak</groupId>
    <artifactId>camel-spring-demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.17.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-spring-boot-starter</artifactId>
            <version>2.21.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-ftp</artifactId>
            <version>2.21.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-csv</artifactId>
            <version>2.21.3</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

谁能指出我哪里出错了?提前致谢!

这是 Maven 过滤的问题。 org.apache.maven.plugins:maven-resources-plugin:2.7:resources 中存在错误。您收到的错误归因于正在创建的 application.properties 文件,而不是您的路由构建器中的更改。

springboot pom的parent 1.5.17.RELEASE引入了maven-resources-plugin 2.7。它具有以下内容以对资源文件应用过滤

    <!-- Turn on filtering by default for application properties -->
    <resources>
        <resource>
            <directory>${basedir}/src/main/resources</directory>
            <filtering>true</filtering>
            <includes>
                <include>**/application*.yml</include>
                <include>**/application*.yaml</include>
                <include>**/application*.properties</include>
            </includes>
        </resource>
        <resource>
            <directory>${basedir}/src/main/resources</directory>
            <excludes>
                <exclude>**/application*.yml</exclude>
                <exclude>**/application*.yaml</exclude>
                <exclude>**/application*.properties</exclude>
            </excludes>
        </resource>
    </resources>

使用 maven-resources-plugin 版本不是 2.7 的 springboot 父版本。

例如

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.0.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>