简体   繁体   English

springboot java应用程序类中的属性值加载

[英]properties value loading in springboot java application class

I am trying to get properties file value loaded in my java Application class, but it is not loading, as Sysout is printing null. 我正在尝试在我的java应用程序类中加载属性文件值,但是由于Sysout打印null,所以它没有加载。 Anything I am missing for my code. 我缺少我的代码。 When I am starting the Spring container, I can see the values of the properties file loaded in the log as below : 当我启动Spring容器时,可以看到如下所示在日志中加载的属性文件的值:

015-12-24 22:36:08.313  INFO 22224 --- [           main] com.ge.predix.solsvc.boot.Application    : propertySource=applicationConfig: [file:./config/application.properties] values={logging.level.org.springframework=INFO, server.port=9092, logging.level.root=INFO}class=class org.springframework.core.env.PropertiesPropertySource
2015-12-24 22:36:08.313  INFO 22224 --- [           main] com.ge.predix.solsvc.boot.Application    : propertySource=class path resource [application-default.properties] values={**predix.oauth.clientId=admin:cargo_beta**, spring.profiles.active=local, predix.oauth.restHost=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}class=class org.springframework.core.io.support.ResourcePropertySource

        @PropertySources({
            @PropertySource("classpath:application-default.properties") 
        })
        @SpringBootApplication
        @Configuration
        public class Application
        {
            private static final Logger log = LoggerFactory.getLogger(Application.class);



            @Value("${predix.oauth.clientId}")   
            private static String loc;



public static void main(String[] args)
        {
            SpringApplication springApplication = new SpringApplication(Application.class);
            ApplicationContext ctx = springApplication.run(args); 

System.out.println("#############################################" +loc);

}
} 

简短的答案是spring不会将值注入到静态成员中: Spring:如何将值注入到静态字段中?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过@Value 获取属性并以编程方式将其放入 application.yml 中。 Java 与 SpringBoot - Get properties by @Value and put it into application.yml programmatically. Java with SpringBoot java.util 中的 getProperty() 方法无法识别 springboot 的 application.properties 中 ${.} 中的键值变量 - getProperty() method in java.util not able to recognize keys value variables in ${.} inside springboot's application.properties 在Java桌面应用程序中加载应用程序属性 - Loading application properties in a Java desktop application SpringBoot微服务如何使用java配置在应用上下文中设置属性 - SpringBoot microservice How to set properties in application context using java configuration 在SpringBoot中通过@Value检索application.properties值 - Retrieve application.properties values via @Value in SpringBoot SpringBoot中application.properties的@Value始终为null - @Value from application.properties in SpringBoot gives null all the time SpringBoot应用程序中的主类 - Main class in SpringBoot Application 应用程序运行后,如何检查应用程序的application.properties 中的属性值? - How can you check the value of a property in application.properties for a springboot application after the application is running? 使用 -Dspring.application.json 从 Json 文件加载 springboot 属性 - loading springboot properties from a Json file using -Dspring.application.json 在 java 中 Dockerize springboot 应用程序 - Dockerize springboot application in java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM