spring 无法配置DataSource:未指定“url”属性,无法配置嵌入式URL//Cant find application.properties

f0ofjuux  于 2023-11-16  发布在  Spring
关注(0)|答案(1)|浏览(149)

我看到了一些解决方案,但我没有一个application.properties文件来更改'url'

  1. 2022-04-19 22:26:58.653 WARN 18764 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Unsatisfied dependency expressed through method 'dataSourceScriptDatabaseInitializer' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
  2. 2022-04-19 22:26:58.655 INFO 18764 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
  3. 2022-04-19 22:26:58.682 INFO 18764 --- [ main] ConditionEvaluationReportLoggingListener :
  4. Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
  5. 2022-04-19 22:26:58.704 ERROR 18764 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
  6. ***************************
  7. APPLICATION FAILED TO START
  8. ***************************
  9. Description:
  10. Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
  11. Reason: Failed to determine a suitable driver class
  12. Action:
  13. Consider the following:
  14. If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
  15. If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

字符串
我不明白,为什么我有问题的数据库,当我还没有使用它呢?我的代码java也许我没有初始化的pom.xml网址

  1. package springClient;
  2. import org.springframework.boot.SpringApplication;
  3. import org.springframework.boot.autoconfigure.SpringBootApplication;
  4. @SpringBootApplication
  5. public class SpringClient {
  6. public static void main(String[] argv){
  7. SpringApplication.run(SpringClient.class);
  8. }
  9. }


And pom.xml dependencies:I m using PostgreSQL Cant understand Maven

  1. <dependencies>
  2. <dependency>
  3. <groupId>org.springframework.boot</groupId>
  4. <artifactId>spring-boot-starter-web</artifactId>
  5. </dependency>
  6. <dependency>
  7. <groupId>org.springframework.boot</groupId>
  8. <artifactId>spring-boot-starter-thymeleaf</artifactId>
  9. </dependency>
  10. <dependency>
  11. <groupId>org.springframework.boot</groupId>
  12. <artifactId>spring-boot-starter-jdbc</artifactId>
  13. </dependency>
  14. <dependency>
  15. <groupId>org.springframework.boot</groupId>
  16. <artifactId>spring-boot-starter-data-jpa</artifactId>
  17. </dependency>
  18. <dependency>
  19. <groupId>junit</groupId>
  20. <artifactId>junit</artifactId>
  21. <version>4.13.2</version>
  22. <scope>test</scope>
  23. </dependency>
  24. <dependency>
  25. <groupId>org.postgresql</groupId>
  26. <artifactId>postgresql</artifactId>
  27. </dependency>
  28. </dependencies>
  29. </project>


请帮助我修复这个错误。或者如果你会发现我的错误,请写如何纠正它:)

atmip9wb

atmip9wb1#

需要创建一个application.properties文件的方式'src/main/resources'和那里写

  1. spring.datasource.url=jdbc:\\link\\
  2. spring.datasource.username=\*of your DB*\
  3. spring.datasource.password=\*of your DB*\
  4. spring.datasource.driver-class-name=org.\*your DB*\.Driver
  5. spring.datasource.hikari.maximumPoolSize=2
  6. spring.jpa.hibernate.ddl-auto=update
  7. spring.jpa.show-sql=true
  8. spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
  9. remote.server.api=http://localhost:8080/api/

字符串

相关问题