#spring-boot #microservices #h2
#spring-boot #микросервисы #h2
Вопрос:
Я пытаюсь использовать базу данных h2 и микросервисы. Но когда я запускаю приложение, оно не запускается, оно показывает ошибки. У меня есть сервер eureka и микросервис продукта. В микросервисе продукта я использовал базу данных h2database. он показывает ошибки.
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception
is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
Caused by: org.springframework.beans.factory.BeanCreationException: 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
Caused by: 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
Caused by: 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
Caused by: 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
Caused by: java.lang.IllegalStateException: Cannot load driver class: org.h2.Driver
Ниже приведена моя зависимость в pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
Ниже приведен мой файл application.properties микросервиса продукта
server.port=8082
eureka.client.service-url.defaultZone=http://localhost:8761/eureka/
spring.datasource.name=SunHome
#H2 settings
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
springspring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
Пожалуйста, помогите мне устранить эти ошибки.
Ответ №1:
Проверьте applcation.properties на наличие «странных» символов, конфигурация которых должна быть правильной.