【发布时间】:2019-10-30 15:09:19
【问题描述】:
我正在使用 Spring Boot、Spring Cloud Config 和 Docker 开发 Web 应用程序。有3个项目。一种是springboot web、Spring Cloud Config Server和MySql Database。我已经将 Spring Boot Web 与 Themeleaf 一起使用。它基本上是执行 CRUD 操作。在开发阶段它工作正常。但是当我在 Docker 中部署它时 Spring-Boot webapp 容器(springboot-thymeleaf-web-crud)给了我以下错误--
应用程序启动失败
说明:
配置数据源失败:未指定“url”属性,无法配置嵌入式数据源。
原因:无法确定合适的驱动程序类
行动:
考虑以下几点: 如果您想要一个嵌入式数据库(H2、HSQL 或 Derby),请将其放在类路径中。 如果您有要从特定配置文件加载的数据库设置,您可能需要激活它(当前没有激活的配置文件)。
我在 Docker Compose 文件上创建了 3 个容器。
version: '3'
services:
springboot-thymeleaf-web-crud:
image: numery/springboot-thymeleaf-web-crud:latest
networks:
- employee-network
ports:
- 8080:8080
depends_on:
- employee-database
- spring-cloud-config-server-employee
spring-cloud-config-server-employee:
image: numery/spring-cloud-config-server-employee:latest
networks:
- employee-network
ports:
- 8888:8888
employee-database:
image: mysql:5
networks:
- employee-network
environment:
- MYSQL_ROOT_PASSWORD=rootpassword
- MYSQL_DATABASE=employee_directory
volumes:
- /home/numery/Docker-Database/employee_directory:/var/lib/mysql
networks:
employee-network:
SpringBoot Web Application.properties 如下所示
spring.application.name=employee-service-mysql
server.port=8080
spring.cloud.config.uri=http://spring-cloud-config-server-
employee:8888
spring.profiles.active=dev
SpringBoot Config Server 提供以下属性--
spring.datasource.url: jdbc:mysql://employee-
database:3306/employee_directory?
useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false
spring.datasource.username: root
spring.datasource.password: rootpassword
spring.datasource.validationQuery: SELECT 1
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.tomcat.max-wait: 20000
spring.tomcat.max-active: 50
spring.tomcat.max-idle: 20
spring.tomcat.min-idle: 15
spring.jpa.properties.hibernate.dialect:
org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.show-sql: true
spring.jpa.format-sql: true
spring.jpa.database: MYSQL
spring.jpa.hibernate.ddl-auto: create
在这 3 个容器中,Mysql 和 Spring Cloud Config 容器工作正常。但是对于 Spring Boot Webapp(springboot-thymeleaf-web-crud) 通过给出上述错误退出。
注意:我在其他一些 SpringBoot Rest API 上使用相同的数据源(Spring Data JPA)配置。哪些工作正常。但这是我第一次使用 SpringBoot Web。我是否需要在数据源上明确定义任何配置。
请帮忙!!
【问题讨论】:
标签: spring spring-boot docker docker-compose spring-config