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

发布于 2022-01-06 16:48:40 字数 1327 浏览 964 评论 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).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酷到爆炸 2022-01-07 01:04:41

解决了,是我使用mybatis的时候将xml生成在src/main/java目录了,然后在pom.xml中配置了

<resource>
    <directory>src/main/java</directory>
    <includes>
        <include>**/*.yml</include>
        <include>**/*.xml</include>
        <include>**/*.properties</include>
    </includes>
</resource>

这样又把默认的配置覆盖了,所以需要加上    

<resource>
    <directory>src/main/resources</directory>
    <includes>
        <include>**/*.yml</include>
        <include>**/*.xml</include>
        <include>**/*.properties</include>
    </includes>
</resource>

确保resources目录中的配置文件能够正常编译打包。

所以以后mapper.xml还是默认生成在resources目录好了。。。。

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文