当前位置: 首页 > 知识库问答 >
问题:

Spring启动(数据)海森布格与检测数据库驱动程序

曹兴贤
2023-03-14

在开发Spring BootRESTendpoint时,我的应用程序会遇到奇怪的(heisenbug)行为。我为每个endpoint项目制作了单独的模块,这也可能与此相关。在细节上,它可以运行一次,但在重新运行后会失败,可能运行一个endpoint,但不会运行另一个,反之亦然。

描述:

无法确定数据库类型 NONE 的嵌入式数据库驱动程序类

行动:

如果你想要一个嵌入式数据库,请在类路径上放置一个受支持的数据库。如果要从特定配置文件加载数据库设置,则可能需要激活它(当前没有配置文件处于活动状态)。

我的gradle配置:

buildscript {
    ext {
        springBootVersion = '1.5.6.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'

version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
    mavenCentral()
}


dependencies {
//  compile('org.springframework.boot:spring-boot-starter-actuator')
    compile('org.springframework.boot:spring-boot-starter-data-rest')
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-hateoas')
    compile('org.springframework.boot:spring-boot-starter-web')
    runtime('mysql:mysql-connector-java')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

和应用

spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
spring.jpa.generate-ddl=true
spring.jpa.show-sql=true

spring.datasource.url = jdbc:mysql://localhost:3306/customers?useSSL=false
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.username = root
spring.datasource.password = root

server.port=8090

我的回购:

@RepositoryRestResource(collectionResourceRel = "customers", path = "customers ")
public interface CustomerRepository extends PagingAndSortingRepository<Customer, Long> {

    List<Customer> findByName(@Param("name") String name);

    @Override
    @RestResource(exported = false)
    void delete(Long id);

    @Override
    @RestResource(exported = false)
    void delete(Customer entity);


}

和我的主要:

@SpringBootApplication
public class CustomerApplication {

    public static void main(String[] args) {
        SpringApplication.run(CustomerApplication.class, args);
    }
}

错误堆栈跟踪:

2017-08-25 11:51:03.316  INFO 14116 --- [           main] c.b.e.s.p.product.ProductApplication     : Starting ProductApplication on PF0MQ6SH with PID 14116 (C:\Users\yevhen.shymko\IdeaProjects\shop\product\out\production\classes started by yevhen.shymko in C:\Users\yevhen.shymko\IdeaProjects\shop)
2017-08-25 11:51:03.321  INFO 14116 --- [           main] c.b.e.s.p.product.ProductApplication     : No active profile set, falling back to default profiles: default
2017-08-25 11:51:03.420  INFO 14116 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@15bb6bea: startup date [Fri Aug 25 11:51:03 CEST 2017]; root of context hierarchy
2017-08-25 11:51:05.007  INFO 14116 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'httpRequestHandlerAdapter' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration; factoryMethodName=httpRequestHandlerAdapter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration; factoryMethodName=httpRequestHandlerAdapter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]]
2017-08-25 11:51:05.068  INFO 14116 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'managementServletContext' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.actuate.autoconfigure.EndpointWebMvcHypermediaManagementContextConfiguration; factoryMethodName=managementServletContext; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/actuate/autoconfigure/EndpointWebMvcHypermediaManagementContextConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration; factoryMethodName=managementServletContext; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.class]]
2017-08-25 11:51:05.696  INFO 14116 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$e6633d19] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-08-25 11:51:06.165  INFO 14116 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-08-25 11:51:06.179  INFO 14116 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2017-08-25 11:51:06.180  INFO 14116 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.16
2017-08-25 11:51:06.600  INFO 14116 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2017-08-25 11:51:06.600  INFO 14116 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3184 ms
2017-08-25 11:51:07.259  INFO 14116 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2017-08-25 11:51:07.272  INFO 14116 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'metricsFilter' to: [/*]
2017-08-25 11:51:07.273  INFO 14116 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-08-25 11:51:07.273  INFO 14116 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-08-25 11:51:07.273  INFO 14116 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-08-25 11:51:07.274  INFO 14116 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2017-08-25 11:51:07.274  INFO 14116 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'webRequestLoggingFilter' to: [/*]
2017-08-25 11:51:07.274  INFO 14116 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'applicationContextIdFilter' to: [/*]
2017-08-25 11:51:07.445  WARN 14116 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': 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$Tomcat.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
2017-08-25 11:51:07.449  INFO 14116 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2017-08-25 11:51:07.501  INFO 14116 --- [           main] utoConfigurationReportLoggingInitializer : 

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-08-25 11:51:07.519 ERROR 14116 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

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

Description:

Cannot determine embedded database driver class for database type NONE

Action:

If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).


Process finished with exit code 1

共有1个答案

钱弘壮
2023-03-14

解决方案很奇怪 - 在进行一些更改后手动刷新gradle项目。

 类似资料:
  • 嘿,我是Cassandra的新手,我对Spring jdbc模板很友好。 有人能解释一下这两种方法的区别吗?你能建议哪一种更好用吗? 谢谢。

  • 我创建了一个存储空间类型的结构,并创建了一个扫描函数来帮助查询数据库中的行。我有问题插入这种类型。 我可以使用以下sql插入数据; 如果在database/sql/driver中使用值接口; 类型值接口{} 价值是司机必须能够处理的价值。它要么是nil,要么是以下类型之一的实例: int64 浮动64 布尔 []字节 字符串[*]除行以外的所有位置。下一步。 时间,时间 并使用此代码; 最后,我将

  • 问题内容: 最终用户(开发人员或生产人员)可以推荐一个Sql驱动程序包,最好使用“ database / sql”包。我对Postgres,ODBC,MySql(以及可能用于高容量的其他商品(即,不是Sqlite)的其他商品)感兴趣,这些商品最好可在Windows和/或Linux(最好同时使用)上使用。令我感兴趣的是,它可能需要最近进行了更新/维护,并且必须与最新的Go版本一起使用。效率(吞吐量)

  • 我想做一些有趣的事情,我希望能够动态地构建SQL查询过滤器使用Spring Boot 1.5.9和Spring Data Rest,而不需要编写控制器。我觉得我可能走在正确的道路上,但我有点卡住了。 这个想法是通过使用HandlerInterceptorAdapter截取HTTP请求GET方法,并将请求查询参数存储到PagingAndSortingRepository可以使用的对象中。计划是重写S

  • IBM提供了“Redis Composer for Redis”作为Redis管理服务。为此,我们可以配置Redis连接,如下所示。 https://developer.ibm.com/tutorials/access-ibm-cloud-redis-from-a-spring-boot-application/ 我使用SSL=false尝试了下面提到的解决方案,但它并没有像预期的那样工作。没有杰

  • 我在本地有一个引导corda网络,并将这些工件分发给相应的VM。当我启动其中一个节点时,我收到以下错误:我使用azure sql作为后端,并且使用corda Enterprise 4.3编译了jar,并且使用的数据库驱动程序是jdbc 6.4。 IntelliJ项目目标设置为仅Javajdk 1.8。 基本信息。-数据库连接url是< br> : jdbc:sqlserver://