Intellij IDEA complains cannot resolve spring boot properties but they work fine
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
IntelliJ IDEA is a very popular Integrated Development Environment (IDE) widely used for Java development, including Spring Boot applications. Despite its powerful features and robust support for Spring Boot, developers sometimes encounter an issue where IntelliJ IDEA complains that it "cannot resolve" Spring Boot properties. Interestingly, these properties often work perfectly fine when the application is run. Understanding this problem requires delving into how IntelliJ IDEA processes these properties and incorporates them into the Spring Boot framework.
Understanding the Issue
How Spring Boot Manages Properties
Spring Boot uses a hierarchical property management system where properties can be defined in externalized configuration files such as application.properties or application.yml. These configuration files allow developers to customize the application's behavior.
Spring Boot also provides configuration assistance through the @ConfigurationProperties annotation to bind properties to POJO classes. This feature facilitates the management of configuration values, making the application more flexible and easier to manage.
IntelliJ IDEA's Role
IntelliJ IDEA provides code assistance features such as syntax highlighting, autocompletion, and error detection. The IDE uses its internal mechanism to resolve these properties and make them available during design time. However, sometimes, this mechanism fails, causing the IDE to show warnings or errors such as "cannot resolve property."
Why Properties Work at Runtime
The "cannot resolve" issue typically occurs due to misconfiguration or shortcomings in IntelliJ's indexing or resolution process. Despite these warnings, the properties work correctly at runtime due to several factors:
- Execution Context: At runtime, Spring Boot uses its own mechanism to resolve properties. This process is independent of IntelliJ IDEA's configuration resolution.
- Profile Activation: Sometimes, properties belong to a profile that isn't active during development but is activated at runtime, leading IntelliJ IDEA to misinterpret property availability.
- Custom Property Sources: IntelliJ IDEA might not recognize custom property sources that are resolved at runtime via programmatic means, such as environment variables or additional properties files loaded dynamically.
Technical Solutions
Resolving the "cannot resolve" warning involves understanding and addressing the discrepancies between IntelliJ IDEA's setup and Spring Boot's runtime behavior. Here are some common solutions:
Refresh IntelliJ IDEA's Project
- Go to
File>Invalidate Caches / Restart. - Select
Invalidate and Restart. - This action will refresh IntelliJ IDEA's caches, potentially resolving indexing issues.
Ensure Proper spring-boot-configuration-processor Setup
Ensure that your project includes the spring-boot-configuration-processor dependency. This processor is essential for generating metadata used by IntelliJ IDEA for property resolution:
- Use Maven's
compilephase to generate the required Spring configuration metadata file (spring-configuration-metadata.json).
Verify Property Binding
Ensure that the @ConfigurationProperties annotation is correctly applied:
Check Active Profiles
- Verify that the active profile aligns with your current development settings.
- Configure IntelliJ IDEA's "Active Profiles" to match the runtime environment:
- Go to
Run>Edit Configurations. - Under
VM Options, add:-Dspring.profiles.active=dev(or any relevant profile).
Additional Considerations
Plugin Support
Ensure that all necessary plugins are installed and enabled in IntelliJ IDEA:
- Spring Boot
- Spring Assistant
Structural Analysis
Conduct a project-wide analysis to ensure the structure aligns with Spring Boot's conventions. Misplaced or improperly named files can lead to IntelliJ IDEA's inability to resolve properties.
Summary Table
| Solution | Description |
| Refresh Project | Invalidate caches and restart IntelliJ IDEA to clear indexing issues. |
spring-boot-configuration-processor | Ensure this dependency is included to enable metadata generation necessary for property resolution. |
Verify @ConfigurationProperties | Confirm correct usage and structure of property binding classes. |
| Check Active Profiles | Align IntelliJ IDEA's active profiles with the runtime environment to ensure properties are resolved correctly based on profile-specific configurations. |
| Plugin Support | Verify that all necessary plugins are installed and updated to the latest versions. |
| Structural Analysis | Ensure the project structure follows Spring Boot's conventions to facilitate correct property file discovery. |
Conclusion
While the "cannot resolve" issue with Spring Boot properties in IntelliJ IDEA can be frustrating, understanding its origins and employing targeted solutions can help mitigate its impact. By ensuring proper configuration, refreshing your project, and aligning development settings with runtime profiles, you can minimize misinterpretations by the IDE, helping maintain a smooth development workflow.

