3

i have a problem with my project. Maybe you can help me out a bit. I am currently trying to code a little webapp. I use Spring Boot + Vaadin 14 for it. When i test the application in eclipse, everything works as designed. But after i compile my project with Maven and start it, i am greeted with an error message, that my application can´t find any routes.

This is the error message:

Could not navigate to ''
Reason: Couldn't find route for ''

Available routes:
This detailed message is only shown when running in development mode.

This is my pom:

?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.9.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>(REMOVED FOR PRIVACY REASONS)</groupId>
    <artifactId>(REMOVED FOR PRIVACY REASONS)</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>mobileissuecreator</name>
    <packaging>jar</packaging>

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

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-spring-boot-starter</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>
        <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>
</project>

My application starter class:

package com.cen.spin.mobileissuecreator.springcontroller;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.annotation.SessionScope;


import com.vaadin.flow.spring.annotation.EnableVaadin;

@Configuration
@SpringBootApplication
@EnableVaadin("(REMOVED FOR PRIVACY REASONS)")
public class (REMOVED FOR PRIVACY REASONS) extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run((REMOVED FOR PRIVACY REASONS).class, args);
    }

    @Bean
    @SessionScope
    public MICService micService(EnoviaAuthService enoviaAuthService, EnoviaAuthProperties enoviaAuthProperties) {
        return new MICService(enoviaAuthService, enoviaAuthProperties);
    }

    @Bean
    @SessionScope
    public EnoviaAuthService enoviaAuthService(EnoviaAuthProperties enoviaAuthProperties) throws Exception {
        return new EnoviaAuthService(enoviaAuthProperties);
    }

    @Bean
    @SessionScope
    public EnoviaAuthProperties enoviaAuthProperties() {
        return new EnoviaAuthProperties();
    }

    @Bean
    @SessionScope
    public EnoviaRoleSelectorService enoviaRoleSelectorService(EnoviaAuthService enoviaAuthService) {
        return new EnoviaRoleSelectorService(enoviaAuthService);
    }

    @Bean
    @SessionScope
    public EnoviaContextCheckService enoviaContextCheckService(EnoviaAuthService enoviaAuthService) {
        return new EnoviaContextCheckService(enoviaAuthService);
    }

}

Would be really great if you could help me.

Thanks!

Tom D.
  • 33
  • 1
  • 3
  • do you have a View with a [`@Route` annotation](https://vaadin.com/docs/v14/flow/routing/tutorial-routing-annotation.html)? – kscherrer Oct 17 '19 at 07:22
  • Yes. Every View has a @Route annotation. Meanwhile i found a workaround. If i put all of my Classes in the same package, it will work after being compiled. Is it not possible to have classes in different packages? – Tom D. Oct 17 '19 at 07:50

1 Answers1

3

The problem is because your configuration class only scans the package it is defined in and all its subpackages by default.

So in order to fix your problem, you should do one of these:

  • define additional packages to be scanned, that are not yet scanned by default. You can do this in the @SpringBootApplication annotation with the scanBasePackages attribute.

  • Move the configuration class further up in the package structure, so that all necessary spring-components and vaadin views are within the same (or sub-) package as the configuration, so they will be scanned by default.

Similar question with multiple answers

kscherrer
  • 5,486
  • 2
  • 19
  • 59