I was given a Kotlin/Spring Boot application and want to run it locally using my IDE…
- User
I was given a Kotlin/Spring Boot application and want to run it locally using my IDE (IntelliJ IDEA). When I try, Flyway reports an error "Unable to obtain connection from database: The connection attempt failed." I don't even know which database it's trying to connect to because it's not part of the exception trace, so how can I make it print this information on startup (or in the error logs)?
Assistant
To see which database Flyway is trying to connect to, you can add these properties to your
application.propertiesorapplication.ymlfile:# For detailed Flyway logging logging.level.org.flywaydb=DEBUG # For general database connection logging logging.level.org.springframework.jdbc=TRACEIf you're using YAML format:
logging: level: org.flywaydb: DEBUG org.springframework.jdbc: TRACEThis will show the full database connection details in your logs, including the URL, username (but not password), and other connection properties.
You can also check your application's configuration files (
application.propertiesorapplication.yml) for the database connection settings, which typically look like:spring.datasource.url=jdbc:postgresql://localhost:5432/dbname spring.datasource.username=user spring.datasource.password=passWould you like me to explain how to troubleshoot further once you see which database it's trying to connect to?
- User
None of this works >_< Goddamn I hate JVM languages
Assistant
I feel your frustration! JVM logging can be incredibly annoying. Let's try a more brute-force approach:
-
Find where your database config is defined. It could be in:
application.propertiesapplication.ymlapplication-local.propertiesapplication-dev.yml- Or even Java/Kotlin config classes with
@Configuration
-
If you're using IntelliJ, try:
- Press Shift twice (Search Everywhere)
- Type "datasource" or "jdbc"
- Look in both files and code
-
Or just search all files:
- Ctrl+Shift+F (Cmd+Shift+F on Mac)
- Search for "datasource", "jdbc:", "spring.datasource"
Would you like me to help you interpret what you find? Sometimes Spring Boot apps use really obscure ways of configuring databases, like environment variables or external config servers, which can make this extra fun (not).
-