com.vaadin.flow.router.RouteNotFoundError - 找不到 'sw.js' 的路线

com.vaadin.flow.router.RouteNotFoundError - Couldn't find route for 'sw.js'

我在 Vaadin 8 中构建了一个小型 Web 应用程序并迁移到了 Vaadin 14 MPR。组件正在显示,但在 jetty:run 期间出现异常,如下所示

[qtp729679840-28] 信息 com.vaadin.flow.router.RouteNotFoundError - 找不到 'sw.js' 的路线 com.vaadin.flow.router.NotFoundException:找不到 'sw.js'

的路线

我已经添加了 pom.xml 中所示的依赖项。我正在尝试向 Vaadin 8 设计器文件添加一个或多个组件,该文件只有两个垂直布局。

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>org.example</groupId>
<artifactId>vaadin-8-to-14-mpr-1</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>vaadin-8-to-14-mpr-1</name>

<prerequisites>
    <maven>3</maven>
</prerequisites>

<properties>
    <vaadin.version>14.8.1</vaadin.version>
    <vaadin.plugin.version>14.8.1</vaadin.plugin.version>
    <vaadin.setup.version>8.14.3</vaadin.setup.version>
    <jetty.plugin.version>9.4.36.v20210114</jetty.plugin.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <!-- If there are no local customizations, this can also be "fetch" or "cdn" -->
    <vaadin.widgetset.mode>local</vaadin.widgetset.mode>
</properties>

<repositories>
    <repository>
        <id>vaadin-addons</id>
        <url>http://maven.vaadin.com/vaadin-addons</url>
    </repository>
    <repository>
        <id>osgeo</id>
        <name>OSGeo Release Repository</name>
        <url>https://repo.osgeo.org/repository/release/</url>
        <snapshots><enabled>false</enabled></snapshots>
        <releases><enabled>true</enabled></releases>
    </repository>
</repositories>

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

<dependencies>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.0.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-server</artifactId>
        <version>${vaadin.setup.version}</version>
        <exclusions>
            <exclusion>
                <groupId>org.jsoup</groupId>
                <artifactId>jsoup</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.google.gwt</groupId>
                <artifactId>gwt-elemental</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <!--        <dependency>
    <groupId>com.vaadin</groupId>
    <artifactId>vaadin-push</artifactId>
    <version>${vaadin.setup.version}</version>
  </dependency>
<dependency>
    <groupId>com.vaadin</groupId>
    <artifactId>vaadin-client-compiled</artifactId>
  </dependency>-->
    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-themes</artifactId>
                <version>${vaadin.setup.version}</version>
    <!--    <version>8.13.3</version>-->
    </dependency>
    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-core</artifactId>
        <version>14.8.1</version>
    </dependency>
    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>mpr-v8</artifactId>
        <version>2.2.3</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.7.25</version>
    </dependency>

    <dependency>
        <groupId>org.vaadin.addon</groupId>
        <artifactId>v-leaflet</artifactId>
        <version>2.0.3</version>
    </dependency>
    <dependency>
        <groupId>org.locationtech.jts</groupId>
        <artifactId>jts-core</artifactId>
        <version>1.16.0</version>
    </dependency>
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-geojson</artifactId>
        <version>14.5</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>3.2.0</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
                <!-- Exclude an unnecessary file generated by the GWT compiler. -->
                <packagingExcludes>WEB-INF/classes/VAADIN/widgetsets/WEB-INF/**</packagingExcludes>
            </configuration>
        </plugin>
        <plugin>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-maven-plugin</artifactId>
            <version>8.7.0</version>
            <executions>
                <execution>
                    <goals>
                        <goal>resources</goal>
                <!--        <goal>update-theme</goal>-->
                        <goal>update-widgetset</goal>
                        <goal>compile</goal>
                        <!-- Comment out compile-theme goal to use on-the-fly theme compilation -->
                    <!--    <goal>compile-theme</goal>-->
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-clean-plugin</artifactId>
            <version>3.0.0</version>
            <!-- Clean up also any pre-compiled themes -->
            <configuration>
                <filesets>
                    <fileset>
                        <directory>src/main/webapp/VAADIN/themes</directory>
                        <includes>
                            <include>**/styles.css</include>
                            <include>**/styles.scss.cache</include>
                        </includes>
                    </fileset>
                </filesets>
            </configuration>
        </plugin>

        <plugin>
        <groupId>com.vaadin</groupId>
        <artifactId>flow-maven-plugin</artifactId>
        <version>2.7.6</version>
        <executions>
            <execution>
                <goals>
                    <goal>prepare-frontend</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

        <!-- The Jetty plugin allows us to easily test the development build by
            running jetty:run on the command line. -->
        <plugin>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>${jetty.plugin.version}</version>
            <configuration>
                <scanIntervalSeconds>2</scanIntervalSeconds>
            </configuration>
        </plugin>
    </plugins>
</build>

<profiles>
    <profile>
        <!-- Vaadin pre-release repositories -->
        <id>vaadin-prerelease</id>
        <activation>
            <activeByDefault>false</activeByDefault>
        </activation>

        <repositories>
            <repository>
                <id>vaadin-prereleases</id>
                <url>http://maven.vaadin.com/vaadin-prereleases</url>
            </repository>
            <repository>
                <id>vaadin-snapshots</id>
                <url>https://oss.sonatype.org/content/repositories/vaadin-snapshots/</url>
                <releases>
                    <enabled>false</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
        </repositories>
        <pluginRepositories>
            <pluginRepository>
                <id>vaadin-prereleases</id>
                <url>http://maven.vaadin.com/vaadin-prereleases</url>
            </pluginRepository>
            <pluginRepository>
                <id>vaadin-snapshots</id>
                <url>https://oss.sonatype.org/content/repositories/vaadin-snapshots/</url>
                <releases>
                    <enabled>false</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </pluginRepository>
        </pluginRepositories>
    </profile>
</profiles>

我的JavaUI代码

package org.example;

import com.vaadin.annotations.Theme;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.router.Route;
import com.vaadin.mpr.core.HasLegacyComponents;
import com.vaadin.ui.Button;
import com.vaadin.ui.Notification;
import com.vaadin.ui.TextField;
import org.example.ui.MyUIPresenter;
import org.vaadin.addon.leaflet.LFeatureGroup;
import org.vaadin.addon.leaflet.LMap;
import org.vaadin.addon.leaflet.LOpenStreetMapLayer;
import org.vaadin.addon.leaflet.LTileLayer;
import org.vaadin.addon.leaflet.LeafletLayer;


@Theme("mytheme")
@Route("")
public class MyUI extends Div implements HasLegacyComponents {

  private LTileLayer osmTiles = new LOpenStreetMapLayer();
  private MyUIPresenter myUIPresenter;
  LMap map = new LMap();
  private LFeatureGroup lfg = new LFeatureGroup();
  ;
  LeafletLayer leafletLayer;


  public MyUI() {

    myUIPresenter = new MyUIPresenter();
    final TextField mapText = new TextField();
    mapText.setCaption("Map component");
    map.addBaseLayer(osmTiles, "OSM");
    map.setCenter(51.18641111764806, 10.428327809551346);
    map.setZoomLevel(5);
  /*  myUIPresenter.addComponentToMapLayout(mapText, "left: 30px; top: 50px;");
    //  myUIPresenter.addComponentToMapLayout(map, "z-index: 0");*/
    myUIPresenter.addComponentToMapVerticalLayout(mapText);
    myUIPresenter.addComponentToMapVerticalLayout(map);
    final TextField name = new TextField();
    name.setCaption("Type your name here:");
    myUIPresenter.addComponentToUILayout1(name);
    Button button = new Button("Click Me");
    myUIPresenter.addComponentToUILayout1(button);
    button.addClickListener(e -> {
      Notification.show("Good " + name.getValue() + ". This works");
    });
    add(myUIPresenter.getView());
  }

}

我从 Vaadin 团队得到了答复。 我没有添加@PWA注解。

Vaadin 团队的回答: 可能有 sw.js 是由您在同一台计算机上使用过的以前的应用程序注册的。因此,从浏览器设置中注销服务工作者可能会有所帮助,浏览器针对 URL 注册服务工作者,因此如果您在本地尝试不同的应用程序,注册会与本地主机发生冲突。

解决方法: 添加注解后,异常消失

非常感谢 Mr.Tatu 的帮助。