没有为作用域名称“重新启动”注册任何作用域

时间:2019-03-15 13:44:02

标签: java spring spring-boot-devtools

当尝试使用Spring Boot Devtools启动应用程序时,我得到以下堆栈跟踪。

$null, $date, $rest = ...

这是用于重现问题的pom文件。

2019-03-15T08:20:26,929 WARN  o.s.c.a.AnnotationConfigApplicationContext:557 - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'optionalLiveReloadServer' defined in class path resource [org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration$LiveReloadConfiguration.class]: Unexpected exception during bean creation; nested exception is java.lang.IllegalStateException: No Scope registered for scope name 'restart'
Exception in thread "restartedMain"
....

我可以找到人们有类似问题的问题,但是没有一个“重新启动”范围名称的问题。

我将回答我所发现的问题。

2 个答案:

答案 0 :(得分:0)

看来,在Spring Boot应用程序的main()方法中加载ApplicationContext是造成此问题的原因。

我不得不改变

<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>dispatch</groupId>
<artifactId>dispatch-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>dispatch-java</name>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.3.RELEASE</version>
    <relativePath />
</parent>

<properties>
    <java.version>1.8</java.version>
</properties>

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

<dependencies>
    <!-- Begin Spring Boot dependencies -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-log4j2</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

并且一旦我停止设置 context ,Spring Boot就可以使用Dev Tools正常运行了。

答案 1 :(得分:0)

检查@ComponentScan是否仅使用一次。就我而言,我在@ComponentScan(有主要方法的地方)和SpringMainApplication.java文件中使用了BeanDecleration.java。从@ComponentScan文件中删除BeanDecleration.java后,错误已解决。

相关问题