gpt4 book ai didi

How to resolve "Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured"(如何解决“无法配置数据源:未指定‘url’属性,无法配置嵌入的数据源”)

转载 作者:bug小助手 更新时间:2023-10-25 19:17:31 31 4
gpt4 key购买 nike



I am trying implement open-fiegn call from currrencyexchange module to currencyconversion but I am stuck at this error. Can anyone please help me with this. I have checked other answer and tried to add #spring.datasource.driver-class-name=com.mysql.jdbc.Driver but didn't work.

我正在尝试实现从CurrencyExchange模块到CurrencyConvert的开放字段调用,但我被这个错误卡住了。有谁能帮帮我吗?我已经检查了其他答案,并试图添加#spring.datasource.driver-class-name=com.mysql.jdbc.Driver,但没有奏效。


Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-09-22 21:07:32.787 ERROR [currency-conversion-service,,] 261173 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :

***************************
APPLICATION FAILED TO START
***************************

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 dev are currently active).

pom.xml

Pom.xml


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.hashedin</groupId>
<artifactId>currency-conversion-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>currency-conversion-service</name>
<description>Currency Exchange Service template for HU SDE 22.3.2 Advanced Java track</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>2021.0.1</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-openfeign -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>3.1.4</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.11</version>
</dependency>
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
<version>0.2.1</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.6.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api -->
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.7.3</version>
</plugin>
</plugins>
</build>

</project>

application-properties

应用程序-属性


 spring.application.name=currency-conversion-service
#spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.profiles.active=dev

server.port=8081
spring.cloud.config.enabled=false
eureka.client.serviceUrl.defaultZone=https://hu-22-java-adv-mastereureka-server-urtjok3rza-wl.a.run.app/eureka
eureka.instance.prefer-ip-address=true
eureka.instance.hostname=https://hu-22-java-adv-mastereureka-server-urtjok3rza-wl.a.run.app

eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true

更多回答

You use JPA but have nothing database related configured hence it fails. Configure a datasource and include the proper driver dependency.

您使用JPA,但没有配置任何与数据库相关的内容,因此它失败了。配置数据源并包括适当的驱动程序依赖项。

优秀答案推荐

The spring-boot-starter-data-jpa artifact can integrate with H2 embedded database. Add the following dependencies to your POM.xml:

Spring-Boot-starter-data-JPA构件可以与H2嵌入式数据库集成。将以下依赖项添加到POM.xml:


    <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>

then, add two script files into the src/main/resources folder:

然后,将两个脚本文件添加到src/main/Resources文件夹中:



  • schema.sql for creating the database

  • data.sql for populating the database


Note that with spring data JPA you get a default configuration for embedded database. You do not need to add database configuration to the application.properties file.

请注意,使用Spring data JPA可以获得嵌入式数据库的默认配置。您不需要将数据库配置添加到Applation.Properties文件中。



If you want to use mysql you have to add mysql driver:

如果你想使用mysql,你必须添加mysql驱动程序:


<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>


Add this version of derby in pom.xml:

在pom.xml中添加此版本的derby:


<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.11.1.1</version>
<scope>runtime</scope>
</dependency>

After making changes in pom.xml, force update the maven project

在pom.xml中进行更改后,强制更新maven项目


And add the following in applications.properties file:

并在Applations.Properties文件中添加以下内容:


#JPA
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.database=default
spring.jpa.show-sql=true

#DATASOURCE
spring.datasource.continue-on-error=false
spring.datasource.generate-unique-name=false
spring.datasource.username=app

Maybe problem with the earlier default derby jar dependency

可能是早期默认的derby jar依赖项有问题。


It worked after making the above changes

在进行上述更改后,它起作用了



check the classpath of the resources in your IDE
sometimes it exclude all, so that the application.properties files are not copied to the target folder

检查IDE中资源的类路径有时会排除所有资源,这样就不会将应用程序.properties文件复制到目标文件夹



the solution is easy!

解决方案很简单!


open the pom.xml of project and right click and select "Add as Maven Project" and finally "Reload project"

打开项目的pom.xml,点击鼠标右键选择“Add as Maven Project”,最后选择“Reload Project”


enter image description here
enter image description here


更多回答

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