java build_error ai_generated true

过滤资源 'src/main/resources/application.properties' 中的值 '${db.url}' 失败,项目 com.example:my-app:无法解析占位符 'db.url'。

Failed to filter resource 'src/main/resources/application.properties' with value '${db.url}' for project com.example:my-app: Could not resolve placeholder 'db.url' in value '${db.url}'

ID: java/maven-resource-filtering-error

其他格式: JSON · Markdown 中文 · English
80%修复率
85%置信度
0证据数
2024-10-05首次发现

版本兼容性

版本状态引入弃用备注
8+ active

根因分析

Maven 资源过滤已启用,但占位符 ${db.url} 未在任何属性文件或 POM 中定义。

English

Maven resource filtering is enabled, but the placeholder ${db.url} is not defined in any properties file or POM.

generic

解决方案

  1. 95% 成功率 Define the property in pom.xml
    <properties><db.url>jdbc:mysql://localhost:3306/mydb</db.url></properties>
  2. 90% 成功率 Use a properties file with filtering enabled
    Create src/main/filters/db.properties with db.url=jdbc:mysql://localhost:3306/mydb and add <filters><filter>src/main/filters/db.properties</filter></filters>

无效尝试

常见但无效的做法:

  1. Disabling resource filtering entirely 70% 失败

    Other placeholders may need filtering, and disabling it breaks them.

  2. Adding a random property with a different name 90% 失败

    The placeholder must match exactly; a different name won't be resolved.