While creating my first Spring AI project using Java 17, Spring Boot, and Maven, I faced several issues. The Run button was disabled, Maven synchronization was failing, and Spring Boot imports were showing errors.
After troubleshooting, I managed to fix them. Here's what I learned.
1. Java SDK Not Configured
Error: Module JDK is not defined
Solution:
- Open File → Project Structure → Project.
- Select Java 17 as the Project SDK.
- Go to Modules → Dependencies.
- Set Module SDK to Project SDK.
What I learned: IntelliJ needs a properly configured JDK to compile and run Java applications.
2. Green Run Button Missing
Even though my main() method was correct, the green Run icon was missing.
Solution:
- Right-click
src/main/java. - Select Mark Directory as → Sources Root, if not already marked.
- Open Run → Edit Configurations.
- Create a Maven Run Configuration with the command
spring-boot:run.
What I learned: IntelliJ must recognize the source directory. A Maven Run Configuration also allows the application to be started from the IDE.
3. Maven Sync Failed
Error: com.google.inject.CreationException
Spring Boot imports, including @SpringBootApplication, appeared red.
What worked for me:
- Open Settings → Build Tools → Maven.
- Change Maven home path from Use Maven Wrapper to Bundled (Maven 3).
- Reload all Maven projects.
After reloading, the dependency errors disappeared.
What I learned: Maven downloads and manages project dependencies, while IntelliJ's Maven importer makes them available to the IDE. Changing the Maven version helped in my environment, but it may not fix every Maven synchronization issue.
4. Spring AI API Key Error
Error: Failed to load ApplicationContext
Spring AI attempted to initialize an OpenAI model without the required API credentials.
Solution: Configure the OpenAI API key using an environment variable.
spring.ai.openai.api-key=${OPENAI_API_KEY}
What I learned: Spring Boot uses auto-configuration to create beans during startup. If a required configuration is missing, bean initialization may fail.
Always keep API keys outside source code.
5. Port 8080 Already in Use
While running my application, I encountered another error:
Port 8080 was already in use
Solution:
Stop the previously running application using Ctrl + C.
Alternatively, configure a different port:
server.port=8081
What I learned: Only one application can normally listen on the same IP address and port combination at a time.
Final Result
After fixing the SDK configuration, Maven synchronization, and project settings, my Spring Boot application built successfully, and the Run button started working.
Key Takeaways
- Always verify your Java SDK configuration.
- Make sure
src/main/javais recognized as a Sources Root. - Understand the difference between Maven builds and Maven synchronization.
- Check the actual root cause instead of focusing only on
BUILD FAILURE. - Keep API keys secure using environment variables.
- Understand the difference between configuration errors, dependency issues, and runtime failures.
Conclusion
This experience taught me that debugging is not just about fixing errors. It is also about understanding how different tools work together.
As a Java Backend Developer exploring Spring AI, I realized that understanding Maven, IntelliJ, Spring Boot auto-configuration, and application startup is just as important as writing code.
Every error is an opportunity to learn something new!
Top comments (0)