我正在使用Spring、和Docker开发一个web应用程序。有3个项目。一个是springboot web、springboot服务器和MySql数据库。我和Themeleaf一起使用了Spring。基本上是在执行CRUD操作。在开发阶段,它运行良好。但是,当我在容器中部署它时,会出现以下错误--
应用程序启动失败
描述:
未能配置DataSource:“url”属性未指定,也无法配置嵌入式数据源。
原因:未能确定合适的驱动程序类
操作:
考虑以下几点:如果您想要一个嵌入式数据库(H2、HSQL或Derby),请将其放在类路径上。如果要从特定的配置文件加载数据库设置,则可能需要激活它(当前没有活动的配置文件)。
我已经在Docker文件上创建了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网络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=devSpringBoot 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和容器工作得很好。但是对于springboot(springboot-thymeleaf Webapp)来说,是通过给出上面的错误而退出的。
注意:我在其他一些SpringBoot Rest上使用了相同的datasouce(SpringBoot)配置。效果很好。但这是我第一次使用SpringBoot网络。是否需要显式地定义数据源上的任何配置。
救命啊!!
发布于 2019-06-18 02:02:53
我执行以下任务来解决这个问题--
1)我们应该已经启动并运行了mysql容器。
2)检查ip运行的mysql容器
3)将mysql容器的IP添加到我的springboot web应用程序中--
“jdbc:mysql://172.20.0.2:3306/employee_directory? useSSL=false&serverTimezone =UTC&useLegacyDatetimeCode=false:spring.datasource.url”
4)运行mvn干净,mvn安装并生成SpringBoot网络映像。
5)如果我们放下容器,我们需要再次执行相同的任务。因为Mysql容器每次都获得不同的ip。
发布于 2019-06-17 05:20:51
数据源URL,即spring.datasource.url: jdbc:mysql://employee-可能是错误的。或者应该将数据源url添加到Application.properties文件中。
url应该是jdbc:oracle:thin:@hostname:portNumber/schemaName格式的。
关于进一步的细节和澄清,Not using the hostname and port in jdbc url
https://stackoverflow.com/questions/56624265
复制相似问题