无法解析值“${spring.jpa.hibernate.ddl-auto}”中的占位符“spring.jpa.hibernate.ddl-auto” - Spring Framework (Java 17)

问题描述 投票:0回答:1

我在 Java 17 中的 Spring 应用程序遇到问题,并且收到错误消息“无法解析值“${spring.jpa.hibernate”中的占位符“spring.jpa.hibernate.ddl-auto”。 ddl-auto}”。我检查了我的配置,但我似乎无法弄清楚为什么会发生这种情况。有人可以帮我解决这个问题吗?

配置:这是我的 application-dev.properties 文件的相关部分: *spring.jpa.hibernate.ddl-auto=create *

enter image description here

应用程序上下文:我的应用程序上下文配置为使用主配置类中的@PropertySource注释扫描属性。

故障排除步骤:我已经检查了属性文件位置,验证属性键拼写是否正确,并尝试重建并重新启动我的应用程序,但我仍然遇到此错误。

有人可以帮助我确定为什么这个占位符没有得到解决,并提出解决这个问题的潜在解决方案吗?任何帮助将不胜感激!

检查 application-dev.properties 文件以确保 spring.jpa.hibernate.ddl-auto 属性正确定义如下: spring.jpa.hibernate.ddl-auto=create

验证我的 DevConfig 类(用 @Configuration 和 @PropertySource 注解)正确配置了属性源:

    @Configuration
    @Profile("dev")
    @PropertySource(value={"classpath:application-dev.properties"})
    public class DevConfig {
    
    @Autowired
    private DBService dbService;

    @Value("${spring.jpa.hibernate.ddl-auto}")
    private String ddlAuto;

    @Bean
    public boolean instanciaDB() {
        if ("create".equals(ddlAuto)) { // Compare the value directly
            dbService.instanciaDB();
        }
        return false;
     }
    }
java spring spring-annotations
1个回答
0
投票

对我来说

@PropertySource(value={"classpath:application-dev.properties"})
可能带来的麻烦多于帮助。
在我看来,@Profile("dev") 足以自动将
-dev
添加到
application.properties
文件中。

您的

application-dev.properties
文件位于哪个源文件夹中?

当您使用 IDE 或文件浏览器时

© www.soinside.com 2019 - 2024. All rights reserved.