使IntelliJ知道属性文件 [英] Make IntelliJ aware of a properties file

查看:58
本文介绍了使IntelliJ知道属性文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过某种方式告诉IntelliJ将特定的 .properties 文件加载到项目环境中?我们使用 @PropertySource 批注来加载属性文件,并在多个位置加载已配置属性确定的文件中的替代值,例如:

Is there some way to tell IntelliJ that a particular .properties file will be loaded into a project's environment? We use @PropertySource annotations to load properties files, and in several places load override values from a file determined by an already-configured property, like so:

@Configuration
@PropertySource("classpath:com/example/package/db.properties")
@PropertySource("classpath:com/example/package/db.${db.instance}.properties")
public class DatabaseConfig {
    private @Value("${db.someProperty}") String someDBProperty;
    // ...
}

问题是在这些间接引用的文件之一中,例如 db.test.properties ,IntelliJ不知道是否/如何引用属性文件,因此它无法将任何条目与其用法绑定.(奇怪的是,这些文件中列出的某些属性 some 并未显示为灰色,表示未使用的属性",尽管即使这些都没有给出查找用法"搜索的结果).直接命名的文件没有问题,例如上面的 db.properties .

The problem is that within one of these indirectly referenced files, e.g. db.test.properties, IntelliJ doesn't know if/how the properties file is referenced, so it can't tie any of the entries to their usages. (Bizarrely, some of the properties listed in these files are not greyed out to indicate 'Unused property', though even these give no results for a 'Find usages' search). There is no issue with directly named files, e.g. db.properties above.

除了创建引用它们的其他虚拟 @Configuration 文件之外,是否有其他方法可以将这些文件告诉IntelliJ?

Is there some way to tell IntelliJ about these files short of creating additional dummy @Configuration files that reference them?

推荐答案

可以在项目结构中设置.只要看一下这张照片即可.

This can be set in project structure. Just look at this capture.

这篇关于使IntelliJ知道属性文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆