springboot项目的配置文件没有提示,而且图标也不是小绿叶
IntelliJ IDEA 2022.2.3 (Ultimate Edition)
package club.yueshe.pangu.config;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
/**
* @Author Theodore
* @Date 2019/10/23 16:14
*/
@Data
@Configuration
public class FastDFSConfig {
public static String fastDFSIpAndPort;
/**
* 必须使用 @Autowired ,否则无法注入数据
* @param ipAndPort
*/
@Autowired
public void setFastDFSIpAndPort(@Value("${fastdfs.ipAndPort}") String ipAndPort) {
fastDFSIpAndPort = ipAndPort;
}
}
我可以为你提供一些解决方案来解决你的问题:
添加提示信息和小绿叶图标可以使用IDE工具的插件来帮助解决,比如IntelliJ IDEA插件"YAML/Properties Support"和"Spring Assist Tools"。这些插件可以为你的配置文件提供语法高亮和自动提示功能,同时提供可视化的界面来方便你设置配置项。
可以使用Spring Boot Actuator来直接获取应用程序的环境和版本信息。在pom.xml文件中添加actuator依赖即可。在应用程序启动后,访问"/actuator/info"端点即可获取应用程序信息。
你还可以使用@ConfigurationProperties
注解来将配置文件中的属性映射为Java对象。在这种情况下,你可以通过IDE工具来自动获取属性的名称和默认值,并且还可以对属性进行类型检查。示例代码如下所示:
@ConfigurationProperties(prefix = "myconfig")
public class MyConfigProperties {
private String name;
private String version;
// 省略getter和setter方法
}
在配置文件中,你只需要将属性按照"prefix.name=value"的格式来进行配置即可。示例代码如下所示:
myconfig.name=My Application
myconfig.version=1.0.0
希望这些解决方案可以帮助你解决问题。如果你有任何问题,请随时与我联系。
https://blog.csdn.net/weixin_45295465/article/details/122693166 可以试一下