当前位置: 首页 > 知识库问答 >
问题:

Spring Boot“无法解析占位符”

匡安宜
2023-03-14
java -jar myjar.jar

我有个例外

Caused by: java.lang.IllegalArgumentException: 
Could not resolve placeholder 'sysm.client.api.path' in value "${sysm.client.api.path}"

我也尝试过使用JarLoader和PropertiesLauncher,但运气并不好。

我确实在application.properties中定义了属性sysm.client.api.path,但为了更好地衡量,我还将它作为-d参数-dsysm.client.api.path=my-path添加到命令行中。

注意:IntelliJ没有将其作为a-jar运行;相反,它在一个大型类路径命令行参数中声明所有库,然后使用我的@SpringBootApplication类作为可执行类,这完全不符合Spring Boot的精神!

我想知道为什么这个模块似乎在application.properties加载之前就得到了它的属性,是否有任何方法可以重新排序以便它工作

更新:我仔细检查了jar,应用程序属性在boot-inf/classes/application.properties下。但由于某种原因,应用程序没有在JAR中看到这一点。当我把这些复制到发射目录时,它就会正常工作。不知道为什么这些没有像预期的那样从罐子里捡起来?

<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>commy-group</groupId>
<artifactId>my-app</artifactId>
<version>2.0.1-SNAPSHOT</version>

<name>${project.artifactId}</name>
<url>http://maven.apache.org</url>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.10.RELEASE</version>
</parent>

<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <distribution.root>discovery-service-${project.version}</distribution.root>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <ansible.group>npc</ansible.group>
    <ansible.name>${project.artifactId}</ansible.name>
    <ansible.deploy>2018-1</ansible.deploy>
</properties>

<scm>
    <url>..</url>
    <connection>..</connection>
    <developerConnection>..</developerConnection>
</scm>

<distributionManagement>
    ...
</distributionManagement>

<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>4.1.5.RELEASE</version>
    </dependency>

    <!-- ********************* SPRING ********************* -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.6.1</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.6.1</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-ldap</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-hateoas</artifactId>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
    </dependency>
</dependencies>

<build>
    <finalName>${project.artifactId}</finalName>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <executable>true</executable>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>buildnumber-maven-plugin</artifactId>
            <version>1.4</version>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>create</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <doCheck>false</doCheck>
                <doUpdate>false</doUpdate>
                <shortRevisionLength>8</shortRevisionLength>
            </configuration>
        </plugin>
    </plugins>
</build>

共有1个答案

张承颜
2023-03-14

找到答案了。我们有一个定制部署器,它为一个通用Java应用程序部署所有JAR。当然,这对于SpringBoot应用程序来说并不是必需的,因为所有的jar都是内部的(除了主jar和-bootstrapper.jar之外),但我希望这不会影响应用程序的执行。

但是,当我删除所有多余的JAR时,应用程序突然开始识别嵌入的application.properties。

我很想结束这个问题,但也许这个问题与有同样情况的人有关?还有,我想明白为什么会出现这种行为?(这只发生在某些应用程序中,其他应用程序可以很好地使用多余的jar)

 类似资料:
  • 问题内容: 我对春天还很陌生,所以请问这是一个愚蠢的问题。当我尝试启动程序时,出现以下错误:。执行以下代码时,将引发错误: 资源文件夹中存在一个名为的属性文件,其中包含主机和端口的信息。我不确定在哪里定义(如果有的话)。也许甚至没有定义,这就是问题所在。我需要将其更改为类似的东西还是缺少其他内容? 问题答案: 您没有正确读取属性文件。propertySource应该将参数传递为:或。将注释更改为:

  • 问题内容: 我有我的配置: 我得到错误 我知道这可能缺少属性文件,但是我在类路径中恰好有它。有什么不见了? 我的web.xml: 问题答案: 你的应用程序中可能有多个。尝试在超类的方法上设置一个断点,看看在应用程序启动时是否多次调用了该断点。如果不止一个,则可能需要查看配置属性,以便你的应用程序可以正常启动。

  • 我的数据库配置类: 和AppConfig: } 嗨,我上面有个错误,我不知道怎么修复,你能帮我吗?在添加这个bean之前,我的项目运行良好: }

  • 问题内容: 我正在尝试使用文件中的属性,但它似乎不起作用。 这是我的代码: 此类使用批注获取属性。它也被声明为Spring Service并链接到我的文件: 使用,我将此文件链接到我的文件: 这确实有意义,对吗? 但是,当我尝试启动项目时,Tomcat抛出此异常: 或者,简而言之: 编辑: 这是我的web.xml: 我的infraContext.xml被导入到另一个名为applicationCon

  • 我想对Spring Boot进行JUnit测试,如下所示: 应用程序est.java这样 我的POM是这样的: 当我运行测试时,我得到了以下错误信息 但是当我以普通Java应用程序的形式运行这个应用程序时 它工作得很好! 它怎么了?我应该如何使用Spring Boot进行jUnit测试?非常感谢!

  • 我需要利用JEP库来解析Java中的一些表达式。我正面临着占位符的问题。