从Yaml文件打印属性时为Null

时间:2019-07-18 19:46:24

标签: java spring properties yaml

我正在尝试通过以下操作从yml文件访问属性:

import org.springframework.beans.factory.annotation.Value;

@SpringBootApplication
public class Main {

 @Value("${external.library.url.empik.best.accuracy.book}")
 private static String bestAccuracyBook;

 public static void main(String[] args) throws IOException {
  SpringApplication.run(Main.class, args);
  System.out.println(bestAccuracyBook);
 }

}

,尽管添加了SprnigBoot表示法,但它仍打印null。不知道为什么。

我的application-local.yml文件如下:

external:
  library:
    url:
      meriln:
        romans: www.melin.pl/romans
        sensacja: www.melin.pl/sensacja
      empik:
        guides: https ://www.empik.com/ksiazki/poradniki
        romances: https://www.empik.com/ksiazki/romans
        biographies: https://www.empik.com/ksiazki/biografie-i-dokument
        bestsellers: https://www.empik.com/bestsellery/ksiazki
        crime: https://www.empik.com/ksiazki-sensacja-kryminal
        fantasy: https://www.empik.com/ksiazki/literatura-fantastyka
        concrete.book: https://www.empik.com/%s,%s,ksiazka-p
        best.accuracy.book: https://www.empik.com/ksiazki,31,s?sort=scoreDesc&q=%s

我注意到的是,当我将鼠标放在任何属性上时,它说: cannot resolve configuration property .....

我的pom.xml

....

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

...
    <dependencies>
        ...
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

</project>

1 个答案:

答案 0 :(得分:1)

您不能将<button> <svg> <use xlink:href="/icon/path"></use> </svg> <p class="text">Viewing</p> </button> <button> <svg> <use xlink:href="/icon/path"></use> </svg> <p class="text">Viffdewingsdfsdfasfdfsa</p> </button>放在静态字段上。