How to access application.yml properties via lombok
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>
============ 欢迎各位老板打赏~ ===========
与本文相关的文章
- · Java基础问题13个,你都会哪些?
- · 不重新打包项目并替换部分jar包
- · 接收企微事件回调 Content type ‘text/xml;charset=UTF-8’ not supported
- · springboot使用lock4j实现并发控制
- · springboot全局增加sentinel
- · linux快速搭建轻量级efk日志系统
- · Springboot整合Swagger常用注解
- · swagger隐藏authentication参数
- · Spring Security 中的自定义PreAuthorize 注解
- · Expected one result (or null) to be returned by selectOne(), but found: 2
- · JACKSON和FASTJSON处理返回JSON数据中为NULL字段不显示
- · mybatis报错 : Caused by: java.lang.IllegalStateException: Can not find owner from table.