Solucionado (ver solução)
Solucionado
(ver solução)
3
respostas

Erro Heroku Projeto Próprio

Olá comunidade Alura!

Estou realizando um deploy de uma API em um dos challenges, porém estou recebendo um erro no heroku após a aplicação terminar o build, segue o pedaço do erro:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'usuarioRepository' defined in br.com.alura.controlefinanceiro.repositories.UsuarioRepository defined in @EnableJpaRepositories declared on ControleFinanceiroApplication: Cannot create inner bean '(inner bean)#10c8f62' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#10c8f62': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Unsatisfied dependency expressed through method 'dataSourceScriptDatabaseInitializer' 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.RuntimeException: Failed to load driver class org.postgresql.Driver in either of HikariConfig class loader or Thread context classloader 2022-12-13T23:54:52.732595+00:00 app[web.1]: at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:389) ~[spring-beans-5.

Deixarei também o link do meu projeto do Github: https://github.com/jorgehauck/api-controle-financeiro

Agradeço quem conseguir me ajudar, porque procurei bastante nos foruns pelo erro porém sem solução.

3 respostas
solução!

Oi José!

O erro: nested exception is java.lang.RuntimeException: Failed to load driver class org.postgresql.Driver

Olhando o seu projeto não vi o Postgres nas dependências no pom.xml. Verifica qual banco de dados você está utilizando.

Olá Rodrigo!

Primeiramente muito obrigado pela sua pronta resposta!

Observei que realmente faltou adicionar a dependência do driver do Postgresql no projeto já que eu estou usando o MySQL no projeto porém localmente, mas após adicionar a dependência e também adicionar novas propriedades no arquivo application-prod.properties o heroku ainda sim aponta o mesmo erro do Driver do Postgresql, segue arquivo gerado pelo heroku:

2022-12-14T00:24:40.551845+00:00 app[web.1]: Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.RuntimeException: Failed to load driver class org.postgresql.Driver in either of HikariConfig class loader or Thread context classloader 2022-12-14T00:24:40.551845+00:00 app[web.1]: at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.22.jar!/:5.3.22] 2022-12-14T00:24:40.551845+00:00 app[web.1]: at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.22.jar!/:5.3.22] 2022-12-14T00:24:40.551846+00:00 app[web.1]: ... 110 common frames omitted 2022-12-14T00:24:40.551846+00:00 app[web.1]: Caused by: java.lang.RuntimeException: Failed to load driver class org.postgresql.Driver in either of HikariConfig class loader or Thread context classloader 2022-12-14T00:24:40.551846+00:00 app[web.1]: at com.zaxxer.hikari.HikariConfig.setDriverClassName(HikariConfig.java:491) ~[HikariCP-4.0.3.jar!/:na] 2022-12-14T00:24:40.551846+00:00 app[web.1]: at org.springframework.boot.jdbc.DataSourceBuilder$MappedDataSourceProperty.set(DataSourceBuilder.java:463) ~[spring-boot-2.7.3.jar!/:2.7.3] 2022-12-14T00:24:40.551856+00:00 app[web.1]: at org.springframework.boot.jdbc.DataSourceBuilder$MappedDataSourceProperties.set(DataSourceBuilder.java:357) ~[spring-boot-2.7.3.jar!/:2.7.3] 2022-12-14T00:24:40.551857+00:00 app[web.1]: at org.springframework.boot.jdbc.DataSourceBuilder.build(DataSourceBuilder.java:183) ~[spring-boot-2.7.3.jar!/:2.7.3] 2022-12-14T00:24:40.551857+00:00 app[web.1]: at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration.createDataSource(DataSourceConfiguration.java:48) ~[spring-boot-autoconfigure-2.7.3.jar!/:2.7.3] 2022-12-14T00:24:40.551857+00:00 app[web.1]: at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari.dataSource(DataSourceConfiguration.java:90) ~[spring-boot-autoconfigure-2.7.3.jar!/:2.7.3] 2022-12-14T00:24:40.551858+00:00 app[web.1]: at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] 2022-12-14T00:24:40.551858+00:00 app[web.1]: at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na] 2022-12-14T00:24:40.551858+00:00 app[web.1]: at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] 2022-12-14T00:24:40.551859+00:00 app[web.1]: at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na] 2022-12-14T00:24:40.551859+00:00 app[web.1]: at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.22.

Imagem do application properties de produção: Insira aqui a descrição dessa imagem para ajudar na acessibilidade

Variável de ambiente do heroku Insira aqui a descrição dessa imagem para ajudar na acessibilidadeO link do projeto continua o mesmo caso haja necessidade de uma nova consulta.

Grato!

Rodrigo, boa noite!

Passando para avisar que após eu deletar a aplicação no heroku eu tentei o deploy novamente e obtive sucesso!

Novamente muito obrigado Rodrigo!