Ошибка зависимостей Spring Boot в IntelliJ
Устраните ошибки зависимостей при запуске Spring Boot в IntelliJ IDEA через конфигурацию Application. Решите ClassNotFoundException для Apache HTTP компонентов.
Ошибка конфигурации приложения Spring Boot: проблемы с зависимостями при использовании конфигурации Application в IntelliJ IDEA
Я сталкиваюсь с ошибкой зависимостей при запуске моего приложения Spring Boot через конфигурацию Application в IntelliJ IDEA, тогда как при запуске через конфигурацию Maven всё работает корректно.
Описание проблемы
Мое приложение Spring Boot успешно запускается, когда используется конфигурация Maven с целью spring-boot:run. Коллеги также могут запускать приложение через конфигурацию плагина Spring Boot без проблем.
Однако при запуске приложения через конфигурацию Application в IntelliJ IDEA я получаю следующую ошибку:
-- [ main] o.a.c.c.StandardService : Stopping service [Tomcat]
2025-11-21 12:46:19.030 INFO 77224 --- [ main] .s.b.a.l.ConditionEvaluationReportLogger :
Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2025-11-21 12:46:19.203 ERROR 77224 --- [ main] o.s.b.SpringApplication : Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 's3ServiceImpl': Unsatisfied dependency expressed through field 's3Client': Error creating bean with name 's3client' defined in class path resource [com....configuration/S3Configuration.class]: Failed to instantiate [com.amazonaws.services.s3.AmazonS3]: Factory method 's3client' threw exception with message: org/apache/http/protocol/HttpRequestExecutor
...
Caused by: java.lang.ClassNotFoundException: org.apache.http.protocol.HttpRequestExecutor...
Вопросы
- Почему я наблюдаю различное поведение при использовании разных конфигураций запуска в IntelliJ IDEA?
- Как я могу исправить конфигурацию Application, чтобы устранить ошибку зависимостей?
- Что может вызывать
ClassNotFoundExceptionдляorg.apache.http.protocol.HttpRequestExecutorименно при использовании конфигурации Application?
The dependency error you’re experiencing occurs because IntelliJ IDEA’s Application configuration handles dependencies differently than the Maven run configuration, leading to incomplete classpath resolution for certain dependencies such as Apache HTTP components.
Contents
- Understanding the Configuration Differences
- Root Causes of Dependency Issues
- Solutions for Application Configuration
- Resolving the Apache HTTP ClassNotFoundException
- Best Practices for Spring Boot Development
- Prevention Strategies
Understanding the Configuration Differences
IntelliJ IDEA’s Application configuration and Maven run configuration fundamentally differ in how they resolve and manage dependencies:
-
Maven Configuration: Uses Maven’s dependency‑resolution mechanism, which correctly handles all scopes including
provided,test, andruntime. When you runspring‑boot:run, Maven builds the complete classpath including all necessary dependencies. -
Application Configuration: Relies on IntelliJ’s internal dependency resolver, which may not properly handle all Maven scopes and dependency types. This is why certain dependencies work with Maven but fail with the Application configuration.
As noted in the research findings, “IntelliJ IDEA is not injecting the provided dependencies into the CLASSPATH” and this is why Spring is unable to create the embedded servlet container [source: Stack Overflow].
Root Causes of Dependency Issues
Several factors contribute to the dependency‑resolution problems:
1. Classpath Incompleteness
The Application configuration often doesn’t include all the dependencies that Maven resolves. This is particularly problematic for:
- Dependencies with
providedscope - Transitive dependencies
- Runtime dependencies
According to user reports, “Unless IntelliJ is made aware that the project is a Maven one, it won’t download those dependencies at all” [source: Stack Overflow].
2. Module Configuration Issues
IntelliJ IDEA’s module settings can affect dependency resolution. One user found that “in Project Modules, uncheck main & test so they are not modules” helped resolve dependency issues [source: JetBrains Community].
3. Maven Integration Problems
When IntelliJ doesn’t properly recognize the project as a Maven project, it fails to download and manage dependencies correctly, leading to incomplete classpaths.
Solutions for Application Configuration
Solution 1: Add Dependencies with “Provided” Scope to Classpath
In IntelliJ IDEA 2022.3.1 and later, there’s a specific option to handle this:
- Go to Run > Edit Configurations
- Select your Application configuration
- In the Modify options dropdown, check “Add dependencies with ‘provided’ scope to classpath”
This directly addresses the issue where “dependencies with ‘provided’ scope” are not being included in the classpath [source: Stack Overflow].
Solution 2: Use Spring Boot Run Configuration Instead
The most reliable approach is to use IntelliJ IDEA’s dedicated Spring Boot run configuration:
- Right‑click your main application class
- Select Run ‘YourApplicationName’
- IntelliJ will automatically create a proper Spring Boot run configuration
This configuration is specifically designed for Spring Boot applications and handles dependencies correctly [source: IntelliJ IDEA Documentation].
Solution 3: Configure Maven Integration
Ensure your project is properly recognized as a Maven project:
- Check that the Maven tool window shows your project structure correctly
- Verify that dependencies are downloaded in the Maven tool window
- Right‑click the project and select Maven > Reload Project
As one user noted, “you need to let it scan and add dependencies” for proper integration [source: Reddit].
Resolving the Apache HTTP ClassNotFoundException
The specific ClassNotFoundException: org.apache.http.protocol.HttpRequestExecutor error indicates that Apache HTTP client dependencies are missing from the classpath:
1. Check Dependencies in pom.xml
Verify that you have the Apache HTTP client dependency in your pom.xml:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
</dependency>
2. Verify Dependency Scope
Ensure the dependency is not in provided scope unless you have a specific reason:
<!-- Wrong for this case -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
<scope>provided</scope>
</dependency>
3. Force Dependency Resolution
Add the dependency to Spring Boot’s exclusion list to force resolution:
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</exclusion>
</exclusions>
</dependency>
Then explicitly add the Apache HTTP client dependency.
Best Practices for Spring Boot Development
1. Prefer Spring Boot Run Configuration
Always use IntelliJ IDEA’s Spring Boot run configuration when available, as it provides the most reliable dependency resolution and debugging experience.
2. Regular Dependency Updates
Keep your dependencies updated and consistent:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.7.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
3. Dependency Scoping Best Practices
Use appropriate dependency scopes:
compile: Dependencies needed at compile and runtimeprovided: Dependencies available at runtime (like servlet API)runtime: Dependencies needed at runtime but not compiletest: Dependencies needed for testing only
Prevention Strategies
1. Regular Project Validation
Use IntelliJ’s built‑in tools to validate your project setup:
- File > Invalidate Caches / Restart
- Maven > Reload Project
- File > Project Structure to verify module settings
2. Consistent Development Environment
Ensure all team members use the same IntelliJ IDEA version and settings to avoid configuration discrepancies.
3. Automated Testing
Set up integration tests that verify application startup with different run configurations to catch dependency issues early:
@SpringBootTest
class ApplicationStartupTests {
@Test
void contextLoads() {
// This test verifies the application context loads correctly
}
}
Sources
- IntelliJ Run Configuration Spring Boot vs Maven Issues - Stack Overflow
- Spring Boot | IntelliJ IDEA Documentation
- Run Spring‑boot’s main using IDE - Stack Overflow
- Spring Boot run configuration | IntelliJ IDEA Documentation
- Difficulty Getting Spring Boot Project Working – JetBrains Community
- Application Running via Spring Boot Run but not via IntelliJ Idea - Stack Overflow
- No matter how I create my Spring boot project, IntelliJ is unable to recognize the dependencies - Reddit
Conclusion
The dependency issues you’re experiencing stem from fundamental differences between IntelliJ IDEA’s Application configuration and Maven run configuration in how they handle classpath resolution. The key takeaways are:
- Use Spring Boot run configuration for the most reliable development experience with Spring Boot applications.
- Configure IntelliJ to include “provided” scope dependencies in the classpath when using Application configuration.
- Verify Maven integration and ensure all dependencies are properly downloaded and recognized.
- Check dependency scopes in your
pom.xmlto ensure Apache HTTP components are included. - Regular project validation helps prevent and resolve configuration issues.
By implementing these solutions, you should be able to resolve the ClassNotFoundException and have consistent behavior across different run configurations in IntelliJ IDEA.