You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

IntelliJ中Spring Boot项目application.properties无自动补全等问题求助

Troubleshooting Your Spring Boot Project Issues in IntelliJ

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 (or build.gradle) includes core Spring Boot dependencies like spring-boot-starter-parent and spring-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.properties file, select Mark 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-security entry from your pom.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 @Data properly.
  • Validate Lombok Dependency: Make sure your pom.xml has the correct Lombok dependency (the optional=true flag 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 11:57:31