java - DispatcherServletRegistration Spring启动异常

标签 java spring spring-boot vaadin

请帮忙,我尝试将 Vaadin 放在我的(Spring boot)服务器上,在设置一个简单的示例后,出现以下错误:

无法注册在类路径资源 [com/vaadin/flow/spring/SpringBootAutoConfiguration.class] 中定义的 bean“dispatcherServletRegistration”。具有该名称的 bean 已在类路径资源 [org/springframework/boot/autoconfigure/web/servlet/DispatcherServletAutoConfiguration$DispatcherServletRegistrationConfiguration.class] 中定义,并且覆盖已禁用。

然后,为了纠正错误,我在 application.prop 中写入: spring.main.allow-bean-definition-overriding=true

并出现以下错误:

org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration 中的构造函数的参数 1 需要一个类型为“org.springframework.boot.autoconfigure.web.servlet.DispatcherServletPath”的 bean,但无法找到。

POM.XML:

<?xml version="1.0" encoding="UTF-8"?>

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 洛帕莫科网站 云液 0.0.1-快照 jar

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

<pluginRepositories>
    <pluginRepository>
        <id>maven-annotation-plugin-repo</id>
        <url>http://maven-annotation-plugin.googlecode.com/svn/trunk/mavenrepo</url>
    </pluginRepository>
</pluginRepositories>


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

    <relativePath/> <!-- lookup parent from com.lopamoko.cloudliquid.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</artifactId>
    </dependency>
    <dependency>
        <groupId>ru.leon0399</groupId>
        <artifactId>dadata</artifactId>
        <version>0.8.0</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>
    <dependency>
        <groupId>io.github.openfeign</groupId>
        <artifactId>feign-okhttp</artifactId>
        <version>9.3.1</version>
    </dependency>
    <dependency>
        <groupId>io.github.openfeign</groupId>
        <artifactId>feign-gson</artifactId>
        <version>9.3.1</version>
    </dependency>
    <dependency>
        <groupId>io.github.openfeign</groupId>
        <artifactId>feign-slf4j</artifactId>
        <version>9.3.1</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.dataformat</groupId>
        <artifactId>jackson-dataformat-xml</artifactId>
    </dependency>
    <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</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-data-jpa</artifactId>
        <version>2.1.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-mail</artifactId>
        <version>2.0.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>io.sentry</groupId>
        <artifactId>sentry</artifactId>
        <version>1.7.16</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.0</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot</artifactId>
        <version>2.1.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.modelmapper</groupId>
        <artifactId>modelmapper</artifactId>
        <version>0.7.4</version>
    </dependency>
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>42.2.5</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.5.6</version>
    </dependency>
    <dependency>
        <groupId>com.google.firebase</groupId>
        <artifactId>firebase-admin</artifactId>
        <version>6.6.0</version>
    </dependency>
    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-spring-boot-starter</artifactId>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-bom</artifactId>
            <version>${vaadin.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

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

它是我的主要应用程序:

@SpringBootApplication()
@EntityScan("com/lopamoko/cloudliquid/dataModel")
@EnableJpaRepositories(basePackages =    "com.lopamoko.cloudliquid.repository")
public class CloudliquidApplication extends SpringBootServletInitializer {

public static void main(String[] args) {
    ApplicationContext ctx = SpringApplication.run(CloudliquidApplication.class, args);
    System.out.println("Let's inspect the beans provided by Spring Boot:");

    String[] beanNames = ctx.getBeanDefinitionNames();
    Arrays.sort(beanNames);
    for (String beanName : beanNames) {
        System.out.println(beanName);
    }
    FirebaseConfig firebaseConfig = new FirebaseConfig();
    firebaseConfig.configurateFirebaseApplication();

}


@Bean
public DadataService dadataService() {
    return new DadataServiceImpl();
}

@Bean
public DadataClient dadataClient() {
    return Feign.builder()
            .client(new OkHttpClient())
            .encoder(new GsonEncoder())
            .decoder(new GsonDecoder())
            .logger(new Slf4jLogger(DadataClient.class))
            .logLevel(Logger.Level.FULL)
            .target(DadataClient.class, "https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/address");
}

@Bean
public CustomerDeliveryService customerDeliveryService() {
    return new CustomerDeliveryServiceImpl();
}

@Bean
public OrderService orderService() {
    return new OrderServiceImpl();
}

@Bean
public YandexService yandexService() {
    return new YandexServiceImpl();
}

@Bean
public CategoryService categoryService() {
    return new CategoryServiceImpl();
}

@Bean
public ShopService shopService() {
    return new ShopServiceImpl();
}


@Bean
public CommentService commentService() {
    return new CommentServiceImpl();
}

@Bean
public RatingService ratingService() {
    return new RatingServiceImpl();
}

@Bean
public ProductService productService() {
    return new ProductServiceImpl();
}


@Bean
public TomcatServletWebServerFactory tomcatFactory() {
    return new TomcatServletWebServerFactory() {
        @Override
        protected void postProcessContext(Context context) {
            ((StandardJarScanner) context.getJarScanner()).setScanManifest(false);
        }
    };
})

和 Vaadin 示例:

@Route("/TestMySelf")
public class MainView extends VerticalLayout {
  public MainView() {
    Label label = new Label("Hello its CloudLiquid");
  }
}

最佳答案

您使用的 vaadin-spring-boot-starter 版本是什么?

来自this ,它说这是某些旧版本的 vaadin-spring-boot-starter 与 Spring Boot 2.1 一起使用时的已知问题,并将在某些较新的版本中修复:

We have another working workaround and are also close to finding the proper fix without the need for the workaround. Regardless which approach we use first, next week we should have platform releases that work with Spring Boot 2.1. (v10, v11 and v12)

Sorry for keeping you on hold before being able updating to Spring Boot 2.1, we should have looked at this earlier - my bad.

然后从发行说明 here ,它说版本10.1.0支持Spring Boot 2.1。所以我的建议是将 vaadin-spring-boot-starter 升级到至少 10.1.0 或最新版本。

关于java - DispatcherServletRegistration Spring启动异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54279057/

相关文章:

java - 如何在 Java 中使用 Scanner 将输入值存储在数组中

java - 使用 Spring Data JPA 进行 HQL 继承

Java - 从已经定义的整数中随机选择

java - 与最新版本 Selenium Webdriver 和 PhantomJs 的兼容性问题

java - Jackson 数组或字符串 : Can not deserialize instance of java. lang.String 超出 START_ARRAY token

java - Intellij idea 显示错误警告

java - hibernate : Why is it trying to drop/create database on startup?

java - 具有相同类名(不同包)的两个 Spring 服务 Bean 即使使用限定符也会抛出错误

Spring Boot : H2 database not saved to file

java - Resilience4j Retry 不重试