无法运行Spring Boot应用程序:无法确定类错误

huangapple go评论59阅读模式
英文:

Unable to run Spring Boot application: Failed to determine class error

问题

Spring Boot在项目的初始阶段抛出以下错误。

我准备从头开始开发一个项目。在编写任何代码之前,我尝试运行应用程序,但出现了以下错误。

OpenJDK 64位服务器VM警告:在JDK 13中已弃用选项-Xverify:none和-noverify,可能会在将来的版本中删除。

  .   ____          _            __ _ _
 /\\ / 大约是 '_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 ==========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.1.0)

2023-06-12T21:33:13.531+05:30  INFO 10624 --- [           main] com.example.food.FoodApplication         : 使用Java 17.0.3启动FoodApplication,PID为10624(F:\YOU_SEE_ME\food\target\classes在F:\YOU_SEE_ME\food中由shaneeqaz启动)
2023-06-12T21:33:13.589+05:30  INFO 10624 --- [           main] com.example.food.FoodApplication         : 未设置活动配置文件,回退到默认配置文件:"default"
2023-06-12T21:33:20.704+05:30  INFO 10624 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : 以DEFAULT模式引导Spring Data JPA仓库。
2023-06-12T21:33:20.883+05:30  INFO 10624 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : 在101毫秒内完成Spring Data仓库扫描。找到0个JPA仓库接口。
2023-06-12T21:33:24.540+05:30  INFO 10624 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : 使用端口8080(http)初始化Tomcat。
2023-06-12T21:33:24.593+05:30  INFO 10624 --- [           main] o.apache.catalina.core.StandardService   : 启动服务[Tomcat]。
2023-06-12T21:33:24.593+05:30  INFO 10624 --- [           main] o.apache.catalina.core.StandardEngine    : 启动Servlet引擎:[Apache Tomcat/10.1.8]
2023-06-12T21:33:25.110+05:30  INFO 10624 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : 初始化Spring嵌入式WebApplicationContext
2023-06-12T21:33:25.113+05:30  INFO 10624 --- [           main] w.s.c.ServletWebServerApplicationContext : 根WebApplicationContext:在11045毫秒内初始化完成
2023-06-12T21:33:25.481+05:30  WARN 10624 --- [           main] ConfigServletWebServerApplicationContext : 上下文初始化期间遇到异常 - 取消刷新尝试:org.springframework.beans.factory.UnsatisfiedDependencyException: 在类路径资源[org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]中定义的名为'dataSourceScriptDatabaseInitializer'的bean创建时,通过方法'dataSourceScriptDatabaseInitializer'参数0表示不满足的依赖项:在类路径资源[org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]中定义的名为'dataSource'的bean创建时,Factory方法'dataSource'引发了异常,异常消息为:无法确定合适的驱动程序类
2023-06-12T21:33:25.486+05:30  INFO 10624 --- [           main] o.apache.catalina.core.StandardService   : 停止服务[Tomcat]。
2023-06-12T21:33:25.601+05:30  INFO 10624 --- [           main] .s.b.a.l.ConditionEvaluationReportLogger : 

启动ApplicationContext时出现错误。要显示条件评估报告,请使用'debug'启用重新运行应用程序。
2023-06-12T21:33:25.668+05:30 ERROR 10624 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
应用程序启动失败
***************************

描述:

无法配置DataSource:未指定'url'属性,且无法配置嵌入式数据源。

原因:无法确定合适的驱动程序类

操作:

请考虑以下事项:
    如果您需要嵌入式数据库(H2、HSQL或Derby),请将其放在类路径中。
    如果您有要从特定配置文件加载的数据库设置,您可能需要激活它(当前没有活动配置文件)。


进程以退出代码1完成

我从start.spring.io生成的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>3.1.0</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.example</groupId>
	<artifactId>food</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>food</name>
	<description>Food Ordering</description>
	<properties>
		<java.version>17</java.version>
英文:

Spring boot throws the following error at the initial step of a project.

I am about to develop a project from scratch. I tried to run the application before writing any code, but the following error pops up.

OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.

  .   ____          _            __ _ _
 /\\ / ___&#39;_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | &#39;_ | &#39;_| | &#39;_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  &#39;  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.1.0)

2023-06-12T21:33:13.531+05:30  INFO 10624 --- [           main] com.example.food.FoodApplication         : Starting FoodApplication using Java 17.0.3 with PID 10624 (F:\YOU_SEE_ME\food\target\classes started by shaneeqaz in F:\YOU_SEE_ME\food)
2023-06-12T21:33:13.589+05:30  INFO 10624 --- [           main] com.example.food.FoodApplication         : No active profile set, falling back to 1 default profile: &quot;default&quot;
2023-06-12T21:33:20.704+05:30  INFO 10624 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2023-06-12T21:33:20.883+05:30  INFO 10624 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 101 ms. Found 0 JPA repository interfaces.
2023-06-12T21:33:24.540+05:30  INFO 10624 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2023-06-12T21:33:24.593+05:30  INFO 10624 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2023-06-12T21:33:24.593+05:30  INFO 10624 --- [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.8]
2023-06-12T21:33:25.110+05:30  INFO 10624 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2023-06-12T21:33:25.113+05:30  INFO 10624 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 11045 ms
2023-06-12T21:33:25.481+05:30  WARN 10624 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name &#39;dataSourceScriptDatabaseInitializer&#39; defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Unsatisfied dependency expressed through method &#39;dataSourceScriptDatabaseInitializer&#39; parameter 0: Error creating bean with name &#39;dataSource&#39; defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method &#39;dataSource&#39; threw exception with message: Failed to determine a suitable driver class
2023-06-12T21:33:25.486+05:30  INFO 10624 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2023-06-12T21:33:25.601+05:30  INFO 10624 --- [           main] .s.b.a.l.ConditionEvaluationReportLogger : 

Error starting ApplicationContext. To display the condition evaluation report re-run your application with &#39;debug&#39; enabled.
2023-06-12T21:33:25.668+05:30 ERROR 10624 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

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

Description:

Failed to configure a DataSource: &#39;url&#39; 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 (no profiles are currently active).


Process finished with exit code 1

My pom.xml file which I generated from start.spring.io is below.

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
	xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
	&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
	&lt;parent&gt;
		&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
		&lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
		&lt;version&gt;3.1.0&lt;/version&gt;
		&lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
	&lt;/parent&gt;
	&lt;groupId&gt;com.example&lt;/groupId&gt;
	&lt;artifactId&gt;food&lt;/artifactId&gt;
	&lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
	&lt;name&gt;food&lt;/name&gt;
	&lt;description&gt;Food Ordering&lt;/description&gt;
	&lt;properties&gt;
		&lt;java.version&gt;17&lt;/java.version&gt;
	&lt;/properties&gt;
	&lt;dependencies&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
		&lt;/dependency&gt;

		&lt;dependency&gt;
			&lt;groupId&gt;com.mysql&lt;/groupId&gt;
			&lt;artifactId&gt;mysql-connector-j&lt;/artifactId&gt;
			&lt;scope&gt;runtime&lt;/scope&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
			&lt;scope&gt;test&lt;/scope&gt;
		&lt;/dependency&gt;
	&lt;/dependencies&gt;

	&lt;build&gt;
		&lt;plugins&gt;
			&lt;plugin&gt;
				&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
				&lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
			&lt;/plugin&gt;
		&lt;/plugins&gt;
	&lt;/build&gt;

&lt;/project&gt;

Further, I noticed that I am getting the same error for existing Spring Boot projects, which were running fine last time.

Much appreciated if you let me know if any environment variables got deleted/modified.

Note: I am a beginner to Spring Boot

答案1

得分: 0

你需要在你的 application.properties 文件中指定要连接的数据库,例如:

url=jdbc:postgresql://localhost:5432/myDatabase
driver=org.postgresql.Driver
username=postgres
password=postgres
port=5432
英文:

You are expected to specify what database you're willing to connect to, in your application.properties file, for example:

url=jdbc:postgresql://localhost:5432/myDatabase
driver=org.postgresql.Driver
username=postgres
password=postgres
port=5432

huangapple
  • 本文由 发表于 2023年6月13日 00:13:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/76458492.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定