6
respostas

Erro ao iniciar o Tomcat

O projeto estava rodando, mas quando eu inseri o application.properties e o Data.sql não está dando um erro de inicialização do tomcat.


# data source
spring.datasource.driverClassName=org.h2.Driver 
spring.datasource.url=jdbc:h2:mem:alura-forum
spring.datasource.username=forum
spring.datasource.password=forum

# jpa
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=update

# h2
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console

Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'h2Console' defined in class path resource [org/springframework/boot/autoconfigure/h2/H2ConsoleAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.servlet.ServletRegistrationBean]: Factory method 'h2Console' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: org.h2.Driver

`

6 respostas

Oi Ana,

Parece ser um problema com a dependência do H2.

Verifica se ele está declarado no pom.xml, e depois faça esse procedimento: clica com o botão direito no projeto e vá em: Maven -> Update Project

Olá, Rodrigo! Resolveu um dos problemas, mas ainda aparece, pelo que eu entendi, que eu preciso habilitar o debug.

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2021-04-20 18:58:10.053 ERROR 15028 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed

Oi Ana,

Posta o log completo que saiu no console do eclipse quando vc tentou rodara classe main.

2021-04-20 18:58:04.954  INFO 15028 --- [  restartedMain] br.com.alura.forum.ForumApplication      : Starting ForumApplication using Java 15.0.2 on DESKTOP-MHELH3J with PID 15028 (C:\Users\anapa\eclipse-workspace\forum\target\classes started by anapa in C:\Users\anapa\eclipse-workspace\forum)
2021-04-20 18:58:04.964  INFO 15028 --- [  restartedMain] br.com.alura.forum.ForumApplication      : No active profile set, falling back to default profiles: default
2021-04-20 18:58:05.194  INFO 15028 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2021-04-20 18:58:05.195  INFO 15028 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2021-04-20 18:58:07.138  INFO 15028 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2021-04-20 18:58:07.327  INFO 15028 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 157 ms. Found 1 JPA repository interfaces.
2021-04-20 18:58:09.364  INFO 15028 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-04-20 18:58:09.391  INFO 15028 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-04-20 18:58:09.392  INFO 15028 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.45]
2021-04-20 18:58:09.660  INFO 15028 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-04-20 18:58:09.661  INFO 15028 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 4464 ms
2021-04-20 18:58:09.935  WARN 15028 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'inMemoryDatabaseShutdownExecutor' defined in class path resource [org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.class]: Unsatisfied dependency expressed through method 'inMemoryDatabaseShutdownExecutor' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: org.h2.Driver 
2021-04-20 18:58:09.948  INFO 15028 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2021-04-20 18:58:09.983  INFO 15028 --- [  restartedMain] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-04-20 18:58:10.053 ERROR 15028 --- [  restartedMain] o.s.boot.SpringApplication               : Application run failed

Pela mensagem o erro do driver do H2 continua.

Faz o seguinte, apague a sua pasta do maven(pasta oculta .m2), que fica localizada no diretório home do seu usuário no computador e execute novamente o procedimento que eu citei acima.

O Maven vai baixar novamente as dependências do projeto depois disso.

Apaguei a pasta e refiz o update do projeto, mas segue com o mesmo erro. A diferença é que mudou o código do erro.


2021-04-21 09:06:29.694  INFO 4696 --- [  restartedMain] br.com.alura.forum.ForumApplication      : Starting ForumApplication using Java 15.0.2 on DESKTOP-MHELH3J with PID 4696 (C:\Users\anapa\eclipse-workspace\forum\target\classes started by anapa in C:\Users\anapa\eclipse-workspace\forum)
2021-04-21 09:06:29.703  INFO 4696 --- [  restartedMain] br.com.alura.forum.ForumApplication      : No active profile set, falling back to default profiles: default
2021-04-21 09:06:29.918  INFO 4696 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2021-04-21 09:06:29.920  INFO 4696 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2021-04-21 09:06:31.622  INFO 4696 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2021-04-21 09:06:31.779  INFO 4696 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 136 ms. Found 1 JPA repository interfaces.
2021-04-21 09:06:33.526  INFO 4696 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-04-21 09:06:33.563  INFO 4696 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-04-21 09:06:33.564  INFO 4696 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.45]
2021-04-21 09:06:33.858  INFO 4696 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-04-21 09:06:33.859  INFO 4696 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3937 ms
2021-04-21 09:06:34.066  WARN 4696 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'inMemoryDatabaseShutdownExecutor' defined in class path resource [org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.class]: Unsatisfied dependency expressed through method 'inMemoryDatabaseShutdownExecutor' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: org.h2.Driver 
2021-04-21 09:06:34.081  INFO 4696 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2021-04-21 09:06:34.116  INFO 4696 --- [  restartedMain] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-04-21 09:06:34.187 ERROR 4696 --- [  restartedMain] o.s.boot.SpringApplication               : Application run failed