dispatcherServletRegistration Spring boot exception

Help please, I try to put Vaadin on my (Spring boot) server and after I set up a simple example, I get the following error:

The bean 'dispatcherServletRegistration', defined in class path resource [com/vaadin/flow/spring/SpringBootAutoConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/DispatcherServletAutoConfiguration$DispatcherServletRegistrationConfiguration.class] and overriding is disabled.

Then, to correct the error, I write in application.prop: spring.main.allow-bean-definition-overriding=true

and get the following error:

Parameter 1 of constructor in org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration required a bean of type 'org.springframework.boot.autoconfigure.web.servlet.DispatcherServletPath' that could not be found.

POM.XML :

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

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.lopamoko cloudliquid 0.0.1-SNAPSHOT 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>

Its my Main application:

@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);
        }
    };
})

And Vaadin sample:

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

Upvotes: 1

Views: 3660

Answers (1)

Ken Chan
Ken Chan

Reputation: 90507

What is the version of vaadin-spring-boot-starter you are using ?

From this , it said this is the known issues when certain old version of vaadin-spring-boot-starter is used with Spring Boot 2.1 and it will be fixed in some newer release :

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.

Then from the release note here, it said version 10.1.0 supports Spring Boot 2.1. So my advice is to upgrade the vaadin-spring-boot-starter to at least 10.1.0 or the latest version.

Upvotes: 2

Related Questions