我使用的是Eclipse版本:2018-09(4.9.0),我已经在eclipse中安装了Spring工具套件(STS),用于构建Sping Boot 应用程序。
Question-〉当我创建新的Spring Starter项目并试图在不添加任何代码的情况下构建我的项目时。构建失败并显示以下错误。
[WARNING] The requested profile "pom.xml" could not be activated because it does not exist.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.1:test (default-test) on project DemoSpringProject: There are test failures.
[ERROR]
[ERROR] Please refer to C:\Users\SP064774\Util-Workspace\DemoSpringProject\target\surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
如果我删除测试文件夹,这是默认的测试。它的工作很好。但为什么会发生这种情况。下面的文件夹是我删除的一个由Spring Boot 项目生成
src/test/java
先谢谢你。
更新
以下是生成的默认测试文件。
@RunWith(SpringRunner.class)
@SpringBootTest
public class DemoSpringProjectApplicationTests {
@Test
public void contextLoads() {
}
}
从引用的文件中记录日志。C:\用户\SP 064774\实用程序-工作区\演示Spring项目\目标\surefire-报告
--------------------------------------------------------------------
Test set: com.example.demo.DemoSpringProjectApplicationTests
-------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 3.473 s
FAILURE! - in com.example.demo.DemoSpringProjectApplicationTests
contextLoads(com.example.demo.DemoSpringProjectApplicationTests) Time
elapsed: 0.002 s <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by:
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name
“配置文件”:未满足通过构造函数参数0表示的依赖项;嵌套的异常是一个嵌套的异常。创建在类路径资源[org/springframework/ Boot /autoconfigure/jdbc/数据源配置$Hikari .class]中定义的名为“dataSource”的Bean时出错:通过工厂方法示例化Bean失败;嵌套的异常是一个嵌套的异常。无法示例化[com.zaxxer.hikari.hikariDataSource]:工厂方法“dataSource”引发了异常;嵌套的异常是一个嵌套的异常。无法确定合适的驱动程序类原因:org.springframework.beans.factory.BeanCreationException:创建在类路径资源[org/springframework/ Boot /autoconfigure/jdbc/数据源配置$Hikari. class]中定义的名为“dataSource”的Bean时出错:通过工厂方法示例化Bean失败;嵌套的异常是一个嵌套的异常。无法示例化[com.zaxxer.hikari.hikariDataSource]:工厂方法“dataSource”引发了异常;嵌套的异常是一个嵌套的异常。无法确定合适的驱动程序类原因:出现异常错误:无法示例化[com.zaxxer.hikari.hikariDataSource]:工厂方法“dataSource”引发了异常;嵌套的异常是一个嵌套的异常。无法确定合适的驱动程序类原因:异常错误:无法确定合适的驱动程序类
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 http://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.1.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>DemoSpringProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>DemoSpringProject</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</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-integration</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
3条答案
按热度按时间3duebb1j1#
您还没有共享您的pom.xml文件,所以我不能确定,但看起来您的类路径上没有数据库驱动程序。您需要在嵌入式数据库(H2或HSQLDB)上添加依赖项,或者设置一个单独的数据库(如MySQL或Postgres),并添加适当的驱动程序作为依赖项。
irtuqstp2#
在eclipse中,转到Windows-〉首选项-〉Java-〉已安装的JRE,并将路径更改为jdk主文件夹
qybjjes13#
将jar插件更新到3.1.1可立即修复此问题:
https://github.com/spring-projects/spring-boot/issues/16846#issuecomment-492792506