IntelliJ中Spring Boot项目application.properties无自动补全等问题求助
Hey there, let's work through these three common issues you're facing with your Spring Boot project in IntelliJ—here's how to fix each one:
1. No Code Autocompletion in application.properties
It's super frustrating when IntelliJ doesn't suggest even basic types like Integer or Spring config properties in your config file. Try these steps:
- Verify the Spring Boot Plugin is Enabled: Go to
File → Settings → Plugins, search for "Spring Boot", and make sure it's checked. If it was disabled, enable it and restart IntelliJ. - Reload Project Dependencies: Double-check your
pom.xml(orbuild.gradle) includes core Spring Boot dependencies likespring-boot-starter-parentandspring-boot-starter-web. Then click the "Reload All Maven Projects" button in the right-side Maven panel (or the refresh button for Gradle) to sync dependencies properly. - Mark the File as a Spring Properties File: Right-click your
application.propertiesfile, selectMark as → Spring Properties File. This tells IntelliJ to treat it as a dedicated Spring config file and enable autocompletion features. - Invalidate Caches & Restart: Sometimes cached data causes random glitches. Go to
File → Invalidate Caches..., select "Invalidate and Restart", and let IntelliJ rebuild its cache from scratch.
2. Redirect to /login When Accessing index.html
This happens because Spring Security is enabled by default if you included the spring-boot-starter-security dependency. Here's how to resolve it:
- Remove Spring Security (If Not Needed): If you don't require authentication for your current setup, just delete the
spring-boot-starter-securityentry from yourpom.xml/build.gradle, reload dependencies, and restart the app. - Configure Security to Allow Static Resources: If you want to keep Spring Security but let users access the homepage, create a security config class:
import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/index.html", "/static/**").permitAll() // Allow access to homepage and static files .anyRequest().authenticated() .and().formLogin(); // Keep login form for protected endpoints } }
Note: For Spring Boot 5.7+, use SecurityFilterChain instead of WebSecurityConfigurerAdapter since it's deprecated.
3. Lombok @Data Annotation Not Highlighted, Import Unrecognized
Lombok relies on IntelliJ's plugin and annotation processing to work correctly. Try these fixes:
- Enable the Lombok Plugin: Go to
File → Settings → Plugins, search for "Lombok", and ensure it's installed and enabled. Restart IntelliJ after enabling it. - Turn On Annotation Processing: Go to
File → Settings → Build, Execution, Deployment → Compiler → Annotation Processors, and check the box for "Enable annotation processing". This lets IntelliJ process Lombok's annotations like@Dataproperly. - Validate Lombok Dependency: Make sure your
pom.xmlhas the correct Lombok dependency (theoptional=trueflag is standard):
<dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency>
- Invalidate Caches Again: Like with the first issue, cached data can break Lombok's integration. Run
File → Invalidate Caches...and restart IntelliJ to rule this out.
内容的提问来源于stack exchange,提问作者Raul Magdalena Catala

