返回

提问 添加收藏

Docker中运行SpringBoot项目找不到数据源的

哎码 发布于 2019年05月15日 (共有1个回帖)

如下是我的application.yml配置,本地使用default环境是好使的,但是打包成镜像之后使用docker环境就不好使了:

server:
  port: 12222

mapper:
  mappers:
    - tk.mybatis.mapper.common.Mapper
  not-empty: true

---

spring:
  profiles: default
  datasource:
    username: root
    password: root
    driver-class-name: com.mysql.cj.jdbc.Driver
    type: com.alibaba.druid.pool.DruidDataSource
    url: jdbc:mysql://localhost:3306/oauth
  application:
    name: center-oauth-test

---

spring:
  profiles: docker
  datasource:
    username: root
    password: root
    driver-class-name: com.mysql.cj.jdbc.Driver
    type: com.alibaba.druid.pool.DruidDataSource
    url: jdbc:mysql://mysql:3306/oauth
  application:
    name: center-oauth

 

启动报错如下:

 

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 (the profiles docker are currently active).

Apache DerbyDockerYMLSpring BootH2
文明上网,理性发言
客户端 Android iPhone WP7