maven 相关问题

Apache Maven是一个构建自动化和项目管理工具,主要用于Java项目。此标记用于与特定Maven版本无关的问题。使用gradle标签代替与Gradle相关的问题。

java.lang.ClassNotFoundException:com.mysql.jdbc.Driver,即使在 classpath 中添加 my-sql-connector.jar 并在 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.3.1</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>crud</artifactId> <version>0.0.1-SNAPSHOT</version> <name>crud</name> <description>springboot crud operation learning</description> <url/> <licenses> <license/> </licenses> <developers> <developer/> </developers> <scm> <connection/> <developerConnection/> <tag/> <url/> </scm> <properties> <java.version>17</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ [32m :: Spring Boot :: [39m [2m (v3.3.1)[0;39m [2m2024-06-24T00:10:45.414+05:30[0;39m [32m INFO[0;39m [35m10472[0;39m [2m---[0;39m [2m[crud] [ main][0;39m [2m[0;39m[36mcom.manav.crud.CrudApplication [0;39m [2m:[0;39m Starting CrudApplication using Java 21.0.3 with PID 10472 (C:\Users\mayank dubey\Documents\workspace-spring-tool-suite-4-4.23.0.RELEASE\crud\target\classes started by mayank dubey in C:\Users\mayank dubey\Documents\workspace-spring-tool-suite-4-4.23.0.RELEASE\crud) [2m2024-06-24T00:10:45.417+05:30[0;39m [32m INFO[0;39m [35m10472[0;39m [2m---[0;39m [2m[crud] [ main][0;39m [2m[0;39m[36mcom.manav.crud.CrudApplication [0;39m [2m:[0;39m No active profile set, falling back to 1 default profile: "default" [2m2024-06-24T00:10:45.993+05:30[0;39m [32m INFO[0;39m [35m10472[0;39m [2m---[0;39m [2m[crud] [ main][0;39m [2m[0;39m[36m.s.d.r.c.RepositoryConfigurationDelegate[0;39m [2m:[0;39m Bootstrapping Spring Data JPA repositories in DEFAULT mode. [2m2024-06-24T00:10:46.045+05:30[0;39m [32m INFO[0;39m [35m10472[0;39m [2m---[0;39m [2m[crud] [ main][0;39m [2m[0;39m[36m.s.d.r.c.RepositoryConfigurationDelegate[0;39m [2m:[0;39m Finished Spring Data repository scanning in 45 ms. Found 1 JPA repository interface. [2m2024-06-24T00:10:46.474+05:30[0;39m [32m INFO[0;39m [35m10472[0;39m [2m---[0;39m [2m[crud] [ main][0;39m [2m[0;39m[36mo.s.b.w.embedded.tomcat.TomcatWebServer [0;39m [2m:[0;39m Tomcat initialized with port 8080 (http) [2m2024-06-24T00:10:46.488+05:30[0;39m [32m INFO[0;39m [35m10472[0;39m [2m---[0;39m [2m[crud] [ main][0;39m [2m[0;39m[36mo.apache.catalina.core.StandardService [0;39m [2m:[0;39m Starting service [Tomcat] [2m2024-06-24T00:10:46.488+05:30[0;39m [32m INFO[0;39m [35m10472[0;39m [2m---[0;39m [2m[crud] [ main][0;39m [2m[0;39m[36mo.apache.catalina.core.StandardEngine [0;39m [2m:[0;39m Starting Servlet engine: [Apache Tomcat/10.1.25] [2m2024-06-24T00:10:46.539+05:30[0;39m [32m INFO[0;39m [35m10472[0;39m [2m---[0;39m [2m[crud] [ main][0;39m [2m[0;39m[36mo.a.c.c.C.[Tomcat].[localhost].[/] [0;39m [2m:[0;39m Initializing Spring embedded WebApplicationContext [2m2024-06-24T00:10:46.539+05:30[0;39m [32m INFO[0;39m [35m10472[0;39m [2m---[0;39m [2m[crud] [ main][0;39m [2m[0;39m[36mw.s.c.ServletWebServerApplicationContext[0;39m [2m:[0;39m Root WebApplicationContext: initialization completed in 1079 ms java.lang.ClassNotFoundException: com.mysql.jdbc.Driver at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526) at java.base/java.lang.Class.forName0(Native Method) at java.base/java.lang.Class.forName(Class.java:534) at java.base/java.lang.Class.forName(Class.java:513) at org.springframework.util.ClassUtils.forName(ClassUtils.java:304) at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.driverClassIsLoadable(DataSourceProperties.java:194) at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:175) at org.springframework.boot.autoconfigure.jdbc.PropertiesJdbcConnectionDetails.getDriverClassName(PropertiesJdbcConnectionDetails.java:49) at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration.createDataSource(DataSourceConfiguration.java:55) at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari.dataSource(DataSourceConfiguration.java:117) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) at java.base/java.lang.reflect.Method.invoke(Method.java:580) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:140) at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:644) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:636) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1337) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1167) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:337) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:335) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:254) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1443) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1353) at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:904) at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:782) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:542) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1337) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1167) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:337) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:335) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:313) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:205) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:952) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:624) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456) at org.springframework.boot.SpringApplication.run(SpringApplication.java:335) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1363) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1352) at com.manav.crud.CrudApplication.main(CrudApplication.java:10) [2m2024-06-24T00:10:46.601+05:30[0;39m [33m WARN[0;39m [35m10472[0;39m [2m---[0;39m [2m[crud] [ main][0;39m [2m[0;39m[36mConfigServletWebServerApplicationContext[0;39m [2m:[0;39m Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Failed to initialize dependency 'dataSourceScriptDatabaseInitializer' of LoadTimeWeaverAware bean 'entityManagerFactory': 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: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception with message: Cannot load driver class: com.mysql.jdbc.Driver [2m2024-06-24T00:10:46.604+05:30[0;39m [32m INFO[0;39m [35m10472[0;39m [2m---[0;39m [2m[crud] [ main][0;39m [2m[0;39m[36mo.apache.catalina.core.StandardService [0;39m [2m:[0;39m Stopping service [Tomcat] [2m2024-06-24T00:10:46.620+05:30[0;39m [32m INFO[0;39m [35m10472[0;39m [2m---[0;39m [2m[crud] [ main][0;39m [2m[0;39m[36m.s.b.a.l.ConditionEvaluationReportLogger[0;39m [2m:[0;39m Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled. [2m2024-06-24T00:10:46.639+05:30[0;39m [31mERROR[0;39m [35m10472[0;39m [2m---[0;39m [2m[crud] [ main][0;39m [2m[0;39m[36mo.s.boot.SpringApplication [0;39m [2m:[0;39m Application run failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Failed to initialize dependency 'dataSourceScriptDatabaseInitializer' of LoadTimeWeaverAware bean 'entityManagerFactory': 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: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception with message: Cannot load driver class: com.mysql.jdbc.Driver at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:326) ~[spring-beans-6.1.10.jar:6.1.10] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:205) ~[spring-beans-6.1.10.jar:6.1.10] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:952) ~[spring-context-6.1.10.jar:6.1.10] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:624) ~[spring-context-6.1.10.jar:6.1.10] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.3.1.jar:3.3.1] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[spring-boot-3.3.1.jar:3.3.1] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456) ~[spring-boot-3.3.1.jar:3.3.1] at org.springframework.boot.SpringApplication.run(SpringApplication.java:335) ~[spring-boot-3.3.1.jar:3.3.1] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1363) ~[spring-boot-3.3.1.jar:3.3.1] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1352) ~[spring-boot-3.3.1.jar:3.3.1] at com.manav.crud.CrudApplication.main(CrudApplication.java:10) ~[classes/:na] Caused by: 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: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception with message: Cannot load driver class: com.mysql.jdbc.Driver at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:795) ~[spring-beans-6.1.10.jar:6.1.10] at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:542) ~[spring-beans-6.1.10.jar:6.1.10] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1337) ~[spring-beans-6.1.10.jar:6.1.10] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1167) ~[spring-beans-6.1.10.jar:6.1.10] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562) ~[spring-beans-6.1.10.jar:6.1.10] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522) ~[spring-beans-6.1.10.jar:6.1.10] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:337) ~[spring-beans-6.1.10.jar:6.1.10] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.1.10.jar:6.1.10] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:335) ~[spring-beans-6.1.10.jar:6.1.10] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-6.1.10.jar:6.1.10] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:313) ~[spring-beans-6.1.10.jar:6.1.10] ... 10 common frames omitted Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception with message: Cannot load driver class: com.mysql.jdbc.Driver at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:648) ~[spring-beans-6.1.10.jar:6.1.10] at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:636) ~[spring-beans-6.1.10.jar:6.1.10] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1337) ~[spring-beans-6.1.10.jar:6.1.10] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1167) ~[spring-beans-6.1.10.jar:6.1.10] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562) ~[spring-beans-6.1.10.jar:6.1.10] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522) ~[spring-beans-6.1.10.jar:6.1.10] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:337) ~[spring-beans-6.1.10.jar:6.1.10] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.1.10.jar:6.1.10] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:335) ~[spring-beans-6.1.10.jar:6.1.10] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-6.1.10.jar:6.1.10] at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:254) ~[spring-beans-6.1.10.jar:6.1.10] at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1443) ~[spring-beans-6.1.10.jar:6.1.10] at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1353) ~[spring-beans-6.1.10.jar:6.1.10] at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:904) ~[spring-beans-6.1.10.jar:6.1.10] at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:782) ~[spring-beans-6.1.10.jar:6.1.10] ... 20 common frames omitted Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception with message: Cannot load driver class: com.mysql.jdbc.Driver at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:177) ~[spring-beans-6.1.10.jar:6.1.10] at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:644) ~[spring-beans-6.1.10.jar:6.1.10] ... 34 common frames omitted Caused by: java.lang.IllegalStateException: Cannot load driver class: com.mysql.jdbc.Driver at org.springframework.util.Assert.state(Assert.java:97) ~[spring-core-6.1.10.jar:6.1.10] at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:175) ~[spring-boot-autoconfigure-3.3.1.jar:3.3.1] at org.springframework.boot.autoconfigure.jdbc.PropertiesJdbcConnectionDetails.getDriverClassName(PropertiesJdbcConnectionDetails.java:49) ~[spring-boot-autoconfigure-3.3.1.jar:3.3.1] at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration.createDataSource(DataSourceConfiguration.java:55) ~[spring-boot-autoconfigure-3.3.1.jar:3.3.1] at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari.dataSource(DataSourceConfiguration.java:117) ~[spring-boot-autoconfigure-3.3.1.jar:3.3.1] at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na] at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:140) ~[spring-beans-6.1.10.jar:6.1.10] ... 35 common frames omitted 我使用 eclipse IDE 在 spring 工具套件中运行这个 main.java 文件,并且我创建了一个在我的数据库实体中执行 CRUD 操作的 API。但是当我运行应用程序时,它一直显示此错误,我已经筋疲力尽,尝试了我在互联网上看到的所有内容仍然面临着这个问题,其他项目中没有连接问题[[在此处输入图像描述](https://i.sstatic。 net/XWdz4R8c.png)](https://i.sstatic.net/nutUBCpP.png) 删除 JDBC 驱动程序依赖项的运行时范围: <scope>runtime</scope> 范围运行时假定依赖项是由运行时提供的,因此它不与应用程序打包在一起。

回答 1 投票 0

无法导入org.springframework.web.bind.annotation.RestController;无法使用@Restcontroller

这是我的代码 包com.example.demo3; 导入 org.springframework.web.bind.annotation.RestController; `@RestController` 公共课 BooksC { //代码 } 这是我的 pom.xml 文件 这是我的代码 package com.example.demo3; import org.springframework.web.bind.annotation.RestController; `@RestController` public class BooksC { //Code } 这是我的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.3.10.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>demo3</artifactId> <version>0.0.1-SNAPSHOT</version> <name>demo3</name> <description>Demo project for Spring Boot</description> <properties> <java.version>11</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> 我已经尝试过其他版本、版本和依赖项 但问题还是一样 我只是想让你用演示类来展示问题BooksC 这里我使用了 spring 初始化器 Eclipse 版本:2021-03 (4.19.0) 您需要添加 REST 依赖项 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-rest</artifactId> </dependency> 您需要将 Spring-web 依赖项添加到您的 pom 文件中 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> 那么它应该可以正常工作

回答 2 投票 0

“导出”不被识别为内部或外部命令

我需要在机器中设置 Maven 选项。我运行了以下命令,但发现“导出”未被识别为内部或外部命令 导出 MAVEN_OPTS=-agentlib:jdwp=transport=dt_socket,地址...

回答 7 投票 0

C# 中如何管理依赖关系?

C# 中如何管理依赖关系?例如,在java中有maven(pom.xml),在JS中有npm(package.json),在C#中有nuget...但是C#中pom.xml的替代品是什么?...

回答 3 投票 0

使用 c# 从 Maven 存储库检索/上传工件

我需要从我的 C# 代码访问 Maven 存储库(上传和检索工件)? 有哪些可用的 C# 库可以完成此任务。 我想我可能需要 C# 等效项来发布答案......

回答 1 投票 0

java hibernate 4 org.hibernate.HibernateException:找不到方言类:org.hibernate.dialect.MYSQLDialect

我正在学习Java EE和Hibernate,我遇到了以下问题: 我在 Eclipse 中创建了一个动态 Web 项目,将其转换为 MAVEN 项目,添加了 mysql-connector-java ...

回答 3 投票 0

在 Github Actions 中获取 Maven 项目版本

我正在尝试获取我的 Maven 项目的版本作为部署过程的一部分,但我似乎在命令的输出中收到错误。有任何想法吗? 我的 pom.xml 插件中有 Maven 帮助...

回答 4 投票 0

我想从 Github Actions 中的 pom.xml 获取项目版本

我的github actions代码如下。我想将版本保存到环境中。 名称:Windows x64 构建 在: 推: 分支:[主要] 拉请求: 分支:[主要] # 让你...

回答 3 投票 0

黄瓜junit运行器java.lang.NoSuchMethodError:

尝试实现cucumber来做一些自动化测试。 j单元测试。我创建了 2 个文件并编辑了 Maven 项目附带的 pom.xml 以添加依赖项。内容如下所示。第一个...

回答 9 投票 0

无法从 GitHub Maven 存储库导入 ntfy.java 包

我尝试在我的项目中使用com.github.maheshbabu11.ntfy.java,但Maven找不到它: 无法执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile (default-compile):

回答 1 投票 0

@MockBean 不适用于 JUnit 5 和 Spring Boot 2 的 @WebMvcTest?

背景: 我在 SpringBoot 2 中有 @RestController ,依赖于 BookSearcherService 。我想模拟 BookSearcherService 以便对控制器进行单元测试。 错误: org.springframework.web.util.

回答 1 投票 0

我面临 Maven 错误:“未知打包:bundle”。有什么建议如何解决吗?

任何人都知道如何修复此错误。 我正在尝试使用 Maven 插件分析我的代码以查找错误。我在打包类型捆绑包时遇到一些错误。 我正在执行的maven命令是mvn

回答 1 投票 0

lionbridge-connector 出现依赖错误

我正在尝试将 Maven 工件从 Nexus 迁移到 Azure Artifacts,但由于“lionbridge-connector.all.author”工件,我遇到了问题。这个文物是 zip 存档,w...

回答 1 投票 0

Maven 错误无法从中央传输工件 org.apache.maven.plugins:maven-source-plugin:pom:3.0.1

我正在尝试使用maven编译我的代码,出现以下错误, 环境 我正在使用 azure devops 服务器并使用构建管道 Maven 错误无法传输工件 org.apache.maven.plugins:

回答 2 投票 0

java.lang.IllegalAccessException:类io.netty.util.internal.PlatformDependent0$6

我试图为暴露Rest API的SpringBoot应用程序实现Redis缓存。附上重要的代码片段和 Maven 构建文件。 启动注释: @SpringBootApplication @EnableAsync @

回答 2 投票 0

Guava 通过 testng 传递性地添加到工件中,在 maven 中添加为测试依赖项

在我的maven项目中,我添加了带有测试范围的testng。 org.testng 测试 在我的 Maven 项目中,我添加了 testng 和 test 范围。 <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>7.1.0</version> <scope>test</scope> </dependency> 我观察到 guava 所依赖的 testng 版本的类文件最终出现在我的 fat jar 中(我用 maven-assembly-plugin 构建了 fat jar)。 Guava 没有直接作为依赖项添加到我的项目中,而是依赖于我在项目中添加的 protobuf-java-util 依赖项。我观察到的是,fat jar 中包含的 guava 类文件来自 testng 依赖的 guava 版本,而不是 protobuf-java-util 依赖的版本 当我从 testng 中排除番石榴时,我可以观察到正确版本的 guava 是从 protobuf-java-util 中传递过来的。 <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>7.1.0</version> <scope>test</scope> <exclusions> <exclusion> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> </exclusion> </exclusions> </dependency> 请注意,我正在观察的模块是一个距根 pom 两层深的嵌套子模块,并且 testng 依赖项位于根 pom 中。我还观察到,如果我更改添加 protobuf-java-util 依赖项的位置,它会优先于从 testng 派生的版本。 我在 mvn:dependency-tree 输出中也观察到了同样的情况,其中 guava 未显示在 protobuf-java-util 下,而是显示在 testng 下(具有 test 范围),当我添加上面的排除项时,它正确显示在protobuf-java-util。 这是什么原因呢?根据我阅读 maven 文档的理解,test作用域依赖项仅用于测试执行,所以我不希望在我的胖罐子中看到它们。 可悲的是,test依赖关系在构建 JAR 时不仅仅被忽略。 Maven 确定每个(传递)依赖项的范围和版本,在您的情况下,范围 compile 获胜(如预期),但似乎 test 依赖项的版本获胜。 一般来说,Maven 依赖调解不值得您太信任。在许多情况下,最好在 POM(或某些父 POM 或 BOM)中定义 <dependencyManagement> 条目来修复某个版本,这样您就不会得到惊喜。

回答 1 投票 0

无法仅在 Kotest 中运行显式标记的测试

我有一个使用kotlin版本1.7.0的spring boot项目。我的 pom 如下所示。 1.7.0 ... 我有一个使用 kotlin 版本 1.7.0 的 Spring Boot 项目。我的 pom 如下所示。 <properties> <kotlin.version>1.7.0</kotlin.version> ... </<properties> <dependencies> <dependency> <groupId>io.kotest</groupId> <artifactId>kotest-runner-junit5-jvm</artifactId> <version>5.3.1</version> <scope>test</scope> </dependency> ... </dependencies> ..... <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>3.0.0-M6</version> <configuration> <forkCount>1</forkCount> <reuseForks>true</reuseForks> <runOrder>alphabetical</runOrder> <useUnlimitedThreads>true</useUnlimitedThreads> <redirectTestOutputToFile>true</redirectTestOutputToFile> <argLine>-Xmx2560m -Dspring.test.context.cache.maxSize=24 --enable-preview ${argLine}</argLine> </configuration> </plugin> 我的 kotest 测试类如下所示, @Tags("CustomTest") class CustomTestClass : FunSpec({ blah blah }) 当我尝试使用以下命令仅运行标记为 CustomTest 的测试时 ./mvnw test -Dkotest.tags="CustomTest" 无论如何,它都会运行项目中的所有测试。谁能帮我调试这个问题吗? 我遵循了 kotest 文档中的这种方法 https://kotest.io/docs/5.3/framework/tags.html 原因可能是命令行中的系统属性 (-Dkotest.tags="CustomTest") 没有传播到用于测试的分叉 JVM。 文档描述了一种从父 JVM 继承这些属性的方法: 要从父配置继承systemProperties集合,您需要在子pom中的systemProperties节点上指定combine.children =“append”: <systemProperties combine.children="append"> <property> [...] </property> </systemProperties>

回答 1 投票 0

maven依赖中的groupId必须与实际jar包匹配吗?

我们的产品中有一个旧罐子。该软件包名称来自几年前收购的一家公司。我正在为其设置 Maven 依赖项,以及在构建后执行本地存储库安装的脚本,所以

回答 2 投票 0

spring-boot-starter-parent 在 pom 文件中到底做了什么?

我正在开发一个项目,它不是Spring boot,也是spring mvc。我的意思是我的项目中没有此类: @SpringBootApplication 公共类应用程序扩展

回答 5 投票 0

如何正确引用Maven项目的子模块

这是我项目的maven结构 动态线程池 |-动态线程池启动器 |-线程池域 |-线程池基础设施 |-线程池类型 |-线程池-应用程序...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.