gpt4 book ai didi

spring - 无法配置数据源:未指定 'url'属性,并且无法配置任何嵌入式数据源。原因:Fa

转载 作者:行者123 更新时间:2023-12-02 19:57:54 25 4
gpt4 key购买 nike

我正在使用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),请将其放在类路径中。
如果您要从特定配置文件中加载数据库设置,则可能需要激活它(当前没有配置文件处于 Activity 状态)。

我在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上使用了相同的datasouce(Spring Data JPA)配置。哪个工作正常。但这是我第一次使用SpringBoot Web。我是否需要在数据源上显式定义任何配置。

请帮忙!!

最佳答案

数据源URL(即spring.datasource.url: jdbc:mysql://employee-)可能是错误的。
或应将您的数据源URL添加到 Application.properties 文件中

网址应采用jdbc:oracle:thin:@hostname:portNumber/schemaName格式

有关更多详细信息和说明,Not using the hostname and port in jdbc url

关于spring - 无法配置数据源:未指定 'url'属性,并且无法配置任何嵌入式数据源。原因:Fa,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56624265/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com