Problem ze startem aplikacji Spring z Gradle

0

Zaczynam pierwsze kroki ze Spring na systemie Linux. Niestety zaraz po stworzeniu podstawowego projektu z użyciem JPA, Web i Actuator i odpalaniem jako Java application uruchomienie nie udaje się. Oto wydruk trace:

2018-12-31 18:13:18.397 ERROR 25282 --- [           main] o.s.b.web.embedded.tomcat.TomcatStarter  : Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Unsatisfied dependency expressed through method 'healthEndpoint' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthIndicatorRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthIndicatorAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthIndicatorRegistry]: Factory method 'healthIndicatorRegistry' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthIndicatorAutoConfiguration': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthIndicatorAutoConfiguration$$EnhancerBySpringCGLIB$$3a6f8c09]: Constructor 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 org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
2018-12-31 18:13:18.410  INFO 25282 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2018-12-31 18:13:18.417  WARN 25282 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
2018-12-31 18:13:18.424  INFO 25282 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-12-31 18:13:18.425 ERROR 25282 --- [           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).

Kompletnie nie wiem jak sobie z tym poradzić. Błąd dostałem na Ubuntu, próbowałem skonfigurować też na Manjaro i miałem to samo. Wydaje mi się to musi być częsty błąd, ale nie znalazłem żadnego rozwiązania. Będę wdzięczny za pomoc.

1

Przecież masz dokładnie tu opisane:

Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class

Coś nie tak z bazą danych, albo masz źle data source skonfigurowany, albo może nie dodałes sterownika JDBC do zalezności ;)

0

Nie używam bazy danych, więc zakładam, że nie muszę nic "robić" przy DataSource. Dodałem JDBC do jar'ów projektu, ale to nic nie pomogło.

0

Nie wiem, co masz w pliku build.gradle, jaką konkretnie komendę odpalasz i jakiej bazy chcesz użyć, bo tego nie napisałeś.

Jeżeli nie chcesz "nic robić", to spróbuj dodać następujące zależności do JPA i H2 (embedded database):

dependencies {
    ... // twoje pozostałe zależności
    compile("org.springframework.boot:spring-boot-starter-data-jpa")
    compile("com.h2database:h2")
}

Pamiętaj też, że H2 używa się do celów developerskich i możesz mieć tam max. 1 połączenie z bazą. W produkcyjnej konfiguracji, powinieneś sobie ustawić jakąś normalną bazę (np. MySQL), którą należy wcześniej zainstalować i uruchomić.

1

Jeśli nie używasz BD to najprościej wyciąć czy tam zakomentować zależnosci do Spring Boot JPA. Możesz zrobić też coś podobnego:
https://stackoverflow.com/questions/36387265/disable-all-database-related-auto-configuration-in-spring-boot

0

Dziękuję scibi92, rozwiązanie ze stackoverflow pomogło.

1 użytkowników online, w tym zalogowanych: 0, gości: 1