首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法在spring boot中加载驱动程序类: org.h2.Driver

无法在spring boot中加载驱动程序类: org.h2.Driver
EN

Stack Overflow用户
提问于 2020-12-09 02:05:03
回答 1查看 172关注 0票数 0

我正在尝试使用h2数据库和微服务。但是当我运行应用程序时,它没有运行,它显示了错误。我有eureka服务器和一个产品微服务。在产品微服务中,我使用了h2database。它正在显示错误。

代码语言:javascript
运行
复制
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中的依赖项

代码语言:javascript
运行
复制
<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>

下面是我的Product microservice的application.properties文件

代码语言:javascript
运行
复制
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  

请帮我解决这个错误。

EN

回答 1

Stack Overflow用户

发布于 2021-09-23 13:04:18

检查applcation.properties中“奇怪”字符的配置是否正确。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65204394

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档