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

Como rodar dois apps SpringBoot na mesma máquina?

Gente, dúvida. To fazendo a formação de Spring e to com o projeto do forum no eclipse, mas quando fui abrir outro projeto maven pra uma API que eu to criando nao consegui fazer funcionar e dá esse erro:

2021-05-03 04:59:37.650  INFO 18948 --- [           main] c.m.c.ColaboradoresApiApplication        : Starting ColaboradoresApiApplication using Java 15.0.2 on DESKTOP-LV5TV6O with PID 18948 (C:\Users\gusta\Downloads\colaboradoresApi\colaboradoresApi\target\classes started by gusta in C:\Users\gusta\Downloads\colaboradoresApi\colaboradoresApi)
2021-05-03 04:59:37.655  INFO 18948 --- [           main] c.m.c.ColaboradoresApiApplication        : No active profile set, falling back to default profiles: default
2021-05-03 04:59:39.101  INFO 18948 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2021-05-03 04:59:39.143  INFO 18948 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 20 ms. Found 0 JPA repository interfaces.
2021-05-03 04:59:40.325  INFO 18948 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-05-03 04:59:40.352  INFO 18948 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-05-03 04:59:40.353  INFO 18948 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.45]
2021-05-03 04:59:40.578  INFO 18948 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-05-03 04:59:40.579  INFO 18948 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2800 ms
2021-05-03 04:59:40.710  WARN 18948 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor 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 org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
2021-05-03 04:59:40.718  INFO 18948 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2021-05-03 04:59:40.748  INFO 18948 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-05-03 04:59:40.786 ERROR 18948 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class


Action:

Consider the following:
    If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
    If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

Por que? O que pode ser?

5 respostas

Enquanto isso, no projeto do forum tudo funciona:

2021-05-03 05:06:19.364  INFO 16108 --- [           main] br.com.alura.forum.ForumApplication      : Starting ForumApplication using Java 15.0.2 on DESKTOP-LV5TV6O with PID 16108 (C:\Users\gusta\Downloads\forum\forum\target\classes started by gusta in C:\Users\gusta\Downloads\forum\forum)
2021-05-03 05:06:19.370  INFO 16108 --- [           main] br.com.alura.forum.ForumApplication      : No active profile set, falling back to default profiles: default
2021-05-03 05:06:21.611  INFO 16108 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-05-03 05:06:21.637  INFO 16108 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-05-03 05:06:21.637  INFO 16108 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.45]
2021-05-03 05:06:21.819  INFO 16108 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-05-03 05:06:21.820  INFO 16108 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2293 ms
2021-05-03 05:06:22.241  INFO 16108 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2021-05-03 05:06:22.641  INFO 16108 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2021-05-03 05:06:22.661  INFO 16108 --- [           main] br.com.alura.forum.ForumApplication      : Started ForumApplication in 4.012 seconds (JVM running for 4.868)

Oi Gustavo,

Você precisa trocar a porta de uma das aplicações, pois ambas estão rodando na porta 8080 e isso vai gerar conflito.

Para trocar a porta adicione esse propriedade:

server.port=8081

Professor, mesmo trocando a porta, ainda não consigo rodar a aplicação. Mais algo que eu possa fazer?

solução!

Pelo Log de erro, você adicionou algum banco de dados como dependência na aplicação(MySQL, Postgresql, etc.) mas não configurou os dados dele no application.properties.

Ou você adiciona as configurações do banco ou remove a dependência dele no pom.xml.

Dá uma conferida nisso.

Realmente, professor. Na verdade, eu havia declarado o Data JPA mas sem fazer as declarações de quais entidades seriam mapeadas, etc. Depois que retirei do pom.xml, funcionou.