分类

链接

2022 年 2 月
 123456
78910111213
14151617181920
21222324252627
28  

近期文章

热门标签

新人福利,免费薅羊毛

现在位置:    首页 > JAVA > 正文
共享办公室出租
How to access application.yml properties via lombok
JAVA 暂无评论 阅读(96)

For getting value from application.yml you should be using @Value from the package org.springframework.beans.factory.annotation.Value but you are using lombok's @Value

<span class="hljs-string">package</span> <span class="hljs-string">com.example.demo;</span>

<span class="hljs-string">import</span> <span class="hljs-string">org.springframework.beans.factory.annotation.Value;</span> <span class="hljs-string">//</span> <span class="hljs-string">Changed</span>
<span class="hljs-string">import</span> <span class="hljs-string">lombok.extern.slf4j.Slf4j;</span>
<span class="hljs-string">import</span> <span class="hljs-string">org.springframework.stereotype.Component;</span>

<span class="hljs-string">@Slf4j</span>
<span class="hljs-string">@Component</span> <span class="hljs-string">//</span> <span class="hljs-attr">EDIT :</span> <span class="hljs-string">Added</span>
<span class="hljs-string">class</span> <span class="hljs-string">Foo</span> {

  <span class="hljs-string">@Value("$</span>{<span class="hljs-string">project.thing.path</span>}<span class="hljs-string">")
  private String projectThingPath;

  public Foo() {
    log.info("</span><span class="hljs-attr">path is:</span> <span class="hljs-string">" + projectThingPath);
  }
}</span>

============ 欢迎各位老板打赏~ ===========

本文版权归Bruce's Blog所有,转载引用请完整注明以下信息:
本文作者:Bruce
本文地址:How to access application.yml properties via lombok | Bruce's Blog

发表评论

留言无头像?