当前位置: 首页 > 知识库问答 >
问题:

Spring启动初始化错误

乐正心思
2023-03-14

我使用spring初始化工具来生成一些工作骨架,我使用MAVEN项目的默认值

https://start.spring.io/

当我运行mvn净安装(在项目中没有做任何更改)时,我得到了以下错误,知道如何克服它吗?

[INFO] Running com.example.restTest.RestTestApplicationTests
12:12:46.554 [main] DEBUG org.springframework.test.context.junit4.SpringJUnit4ClassRunner - SpringJUnit4ClassRunner constructor called with [class com.example.restTest.RestTestApplicationTests]
12:12:46.561 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
12:12:46.568 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
12:12:46.588 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.example.restTest.RestTestApplicationTests] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper]
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.197 s <<< FAILURE! - in com.example.restTest.RestTestApplicationTests
[ERROR] initializationError(com.example.restTest.RestTestApplicationTests)  Time elapsed: 0.005 s  <<< ERROR!
org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.test.context.SpringBootContextLoader]: Unresolvable class definition; nested exception is java.lang.NoClassDefFoundError: org/springframework/boot/context/properties/source/ConfigurationPropertySource
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/context/properties/source/ConfigurationPropertySource
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.properties.source.ConfigurationPropertySource

使现代化

这是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>

    <groupId>com.example</groupId>
    <artifactId>restTest</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>restTest</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-hateoas</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jersey</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot</artifactId>
            <version>1.5.6.RELEASE</version>
        </dependency>
    </dependencies>

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


</project>

更新2

<?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>

<groupId>com.example</groupId>
<artifactId>restTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<name>restTest</name>
<description>Demo project for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.0.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-hateoas</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jersey</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-test</artifactId>
        <scope>test</scope>
    </dependency>
    <!--<dependency>-->
        <!--<groupId>org.springframework.boot</groupId>-->
        <!--<artifactId>spring-boot</artifactId>-->

    <!--</dependency>-->
</dependencies>

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

共有1个答案

夏新翰
2023-03-14

可能是您添加的依赖项

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>

似乎在初始化时需要数据库连接,可能在应用程序上提供数据库连接。属性文件或删除此依赖关系直到数据库构建可能会对您有所帮助。

另外,为了确定确切的原因,请分享您的应用程序。属性文件

 类似资料:
  • 运行代码时,控制台显示以下错误 “初始化引导层java.lang.module.FindException时出错:无法为C:\users\ankit singh\downloads\spring-framework-5.1.9.release\libs\spring-context-indexer-5.1.9.release-sources.jar派生模块描述符,原因是:java.lang.mod

  • 我按照步骤创建了HelloWorld示例,但它没有运行。它给出了以下错误: 初始化引导层java.lang.module.FindException时出错:读取模块:F:\Develop\Eclipse\HelloWorld\bin时出错,原因是:java.lang.module.InvalidModuleDescriptoRexception:HelloWorld.class在顶级目录中找到(模

  • 所以我最近在我的win10 PC上安装了eclipse,并创建了一个公共类。代码如下: 接下来,显示了一个错误: 然后,我删除了info.java文件,并显示以下错误: 我能做些什么来解决这个问题?

  • 我使用的是Windows 10系统,安装了Eclipse,我通过cmd运行java项目,但我需要一个IDE,每次尝试运行类文件时,我都会收到以下错误消息: 启动层初始化期间出错 JAVAlang.module。FindException:找不到模块myproject 或者类似的东西。 这是我正在运行的代码: 请帮忙

  • 在本教程之后,我将尝试实现Spring会话Spring HttpSession教程 但是当我启动应用程序时,我遇到了一个初始化错误。 异常在线程"main"org.springframework.beans.factory.不满意依赖异常:错误创建bean与名称'springSessionRepositoryFilter'定义在类org.springframework.session.data.r

  • 我是第一次使用Eclipse,我刚刚安装完它,我按照我的在线课程的指示键入了下面的代码: 我得到了下面的错误: 初始化引导层java.lang.module.FindException时出错:读取模块:C:\users\seljouki\eclipse-workspace\MyFirstProject\bin时出错,原因是:java.lang.module.InvalidModuleDescrip