![](/img/trans.png)
[英]Get properties by @Value and put it into application.yml programmatically. Java with SpringBoot
[英]properties value loading in springboot java application class
我正在嘗試在我的java應用程序類中加載屬性文件值,但是由於Sysout打印null,所以它沒有加載。 我缺少我的代碼。 當我啟動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.