0

I'm encountering an issue with my Spring application in Java 17, and I'm getting the error message "Could not resolve placeholder 'spring.jpa.hibernate.ddl-auto' in value "${spring.jpa.hibernate.ddl-auto}". I've checked my configuration, but I can't seem to figure out why this is happening. Can someone help me troubleshoot this problem?

Configuration: Here's the relevant part of my application-dev.properties file: *spring.jpa.hibernate.ddl-auto=create *

enter image description here

Application Context: My application context is configured to scan for properties using the @PropertySource annotation in my main configuration class.

Troubleshooting Steps: I've already checked the property file location, verified that the property key is spelled correctly, and tried to rebuild and restart my application, but I'm still encountering this error.

Can someone help me identify why this placeholder is not being resolved and suggest potential solutions to fix this issue? Any assistance would be greatly appreciated!

Checked the application-dev.properties file to ensure that the spring.jpa.hibernate.ddl-auto property is correctly defined as follows: spring.jpa.hibernate.ddl-auto=create

Verified that my DevConfig class (which is annotated with @Configuration and @PropertySource) correctly configures the property source:

    @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;
     }
    }
2
  • Why expose a boolean as a bean? Feels like abusing a bean method to achieve something. Are you using Spring Boot? If so why are you importing the properties yourself and why are you reusing the property from Spring to let Hibernate trigger the creation. Commented Oct 11, 2023 at 6:58
  • Please trim your code to make it easier to find your problem. Follow these guidelines to create a minimal reproducible example. Commented Oct 11, 2023 at 12:41

1 Answer 1

2
  1. For me @PropertySource(value={"classpath:application-dev.properties"}) could cause more trouble than help.
    @Profile("dev") is enough, in my mind, to add automatically -dev to the application.properties file.

  2. In which source folder is your application-dev.properties file?

  3. When you go with your IDE or file explorer under target\classes or classes of your jar, do you find application-dev.properties where you're expecting it being located?

Else, it could be a building problem at Maven (or another tool you are using) packaging phase: a resource not copied where it is expected.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.