Cannot Access: org.springframework.boot.autoconfigure.SpringBootApplication

Compartilhar:

O erro “cannot access org.springframework.boot.autoconfigure.SpringBootApplication” no Spring Boot geralmente ocorre quando há uma incompatibilidade entre a versão do Spring Boot e a versão do Java em uso. Especificamente, este problema é comum quando se utiliza uma versão do Spring Boot acima de 3.0.0 com uma versão do Java que está abaixo da versão 17.

A partir da versão 3.0.0, o Spring Boot exige o uso do Java 17 ou superior. Se um projeto estiver configurado para utilizar uma versão mais antiga do Java (por exemplo, Java 11 ou Java 8), isso resultará em erros de compatibilidade, incluindo a impossibilidade de acessar certas classes e anotações essenciais, como org.springframework.boot.autoconfigure.SpringBootApplication.

Detalhamento do Problema

Ao tentar compilar ou rodar um projeto Spring Boot 3.x com uma versão do Java abaixo de 17, você poderá encontrar erros como:

cannot access org.springframework.boot.autoconfigure.SpringBootApplication
class file for org.springframework.boot.autoconfigure.SpringBootApplication not found

Seu pom.xml:

<groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.0.0</version> versão 3 acima
    <relativePath/>

Solução para o problema:

Se você está utilizando uma versão inferior a 17 do Java, você deve atualizar o seu pom.xml para essas configurações:

Versões no máximo 2.9.x:

 <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.6.4</version>
    <relativePath/>

Assim que trocar as configurações da versão do Spring Starter Parent, utilize o maven para atualizar os Jar para as versões anteriores, em seguida suba a aplicação:

2024-05-28 12:25:38.552  INFO 7512 --- [  restartedMain] b.c.v.AwsRdsSpringBootApplication        : Starting AwsRdsSpringBootApplication using Java 14.0.2 on DESKTOP-R14CJ45 with PID 7512 (C:\Projetos -  Blog Virando Programador\aws-rds-spring-boot\target\classes started by Guilherme in C:\Projetos -  Blog Virando Programador\aws-rds-spring-boot)
2024-05-28 12:25:38.554  INFO 7512 --- [  restartedMain] b.c.v.AwsRdsSpringBootApplication        : No active profile set, falling back to 1 default profile: "default"
2024-05-28 12:25:38.757  INFO 7512 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2024-05-28 12:25:38.758  INFO 7512 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2024-05-28 12:25:40.773  INFO 7512 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2024-05-28 12:25:40.795  INFO 7512 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2024-05-28 12:25:40.795  INFO 7512 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.58]
2024-05-28 12:25:40.946  INFO 7512 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2024-05-28 12:25:40.946  INFO 7512 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2187 ms
2024-05-28 12:25:41.649  INFO 7512 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2024-05-28 12:25:41.706  INFO 7512 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2024-05-28 12:25:41.890  INFO 7512 --- [  restartedMain] b.c.v.AwsRdsSpringBootApplication        : Started AwsRdsSpringBootApplication in 3.924 seconds (JVM running for 5.112)

Resumindo

O erro “cannot access org.springframework.boot.autoconfigure.SpringBootApplication” é um indicativo claro de que há uma incompatibilidade entre a versão do Spring Boot e a versão do Java em uso. Atualizar para o Java 17 ou superior é a solução para garantir que o seu projeto funcione corretamente com o Spring Boot 3.x.

4/5 - (1 vote)
Compartilhar:

Um comentário

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *