【发布时间】:2017-11-09 15:08:23
【问题描述】:
我尝试使用 jpa 而没有 jdbc 来构建我的 spring-boot 项目。 但是出现以下错误:
-> 现在我使用 spring 数据源编辑了我的代码和配置,但我也得到了异常 T T
-> 我已经配置了mysql数据源,但是出现了错误。
我的申请代码如下:
:::
@SpringBootApplication
public class OAuth2Application extends SpringBootServletInitializer {
public static void main(String[] args) {
new SpringApplicationBuilder(OAuth2Application.class)
.initializers(new OAuth2ApplicationContextInitializer())
.run(args);
}
:::
}
[application.yml]
:::
#spring.h2.console:
# enabled: true
# path: /h2-console
#
# 외부 DB 설정시 아래의 주석을 활성화 시킨 후 관련 DB 설정 정보를 입력한다.
#spring:
# datasource:
# url: jdbc:h2:tcp://localhost/~/api;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
# driverClassName: org.h2.Driver
# username: sa
# password:
# DataSource
spring.datasource:
driver-class-name: com.mysql.jdbc.Driver
url: 'jdbc:mysql://localhost:3306/db'
username: user
password: pass
#
# MongoDB data
spring.data:
mongodb:
#uri: mongodb://localhost/
host: localhost
port: 27017
database: db
username: user
password: pass
repositories.enabled: true
#
mybatis:
config-location: 'classpath:mybatis-config.xml'
[my exception log]
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
:::
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]
:::
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
【问题讨论】:
-
我想说删除除@SpringBootAppliation 之外的所有注释并使您的JDBC 工作,然后添加OAuth 的东西。您能否也发布您的 application.properties / application.yml ?
-
为什么要排除
DataSourceAutoConfiguration?那就是自动配置DataSource -
我只想将 jpa 用于 mongoldb...
-
删除另一个注释后,我也得到了以下异常:无法确定数据库类型 NONE 的嵌入式数据库驱动程序类。如果您想要一个嵌入式数据库,请在类路径中放置一个受支持的数据库。如果您有要从特定配置文件加载的数据库设置,您可能需要激活它(当前没有配置文件处于活动状态)。并且无法实例化[org.apache.tomcat.jdbc.pool.DataSource]:工厂方法'dataSource'抛出异常
标签: spring-boot spring-data-jpa datasource