如何构建包含 vaadin 路由和静态 html 页面的 Spring 引导项目

How to build Spring boot project which includes vaadin routes and static html pages

我正在使用 spring bootvaadin 和一些静态 html 页面(ui 框架,如 bootstrap).

我想在我的项目中同时拥有 Vaadin 路由和静态 html 页面。

静态页面只是一个基本的 index.html 页面,其中包括一些 cssjs

1) 如果我将 index.html 放在 webapp 文件夹中,它可以从 www.localhost:8080/ url 访问,但是我从 vaadin 得到错误,说:

the back-end doesn't accept POST requests to www.localhost:8080/

(因为 vaadin 实际上向 url 发送 POST 请求)

2) 如果我添加 @Route("") class,则 index.html 不可访问,但后端会接受来自 POST 的请求vaadin 客户端...

3) 我不知道如何将静态 html 导入 @Route class。 (@HtmlImport 不行)

有什么想法吗?

如果你有一个 spring-boot starter vaadin 应用程序,那么下面应该可以工作:

1) 将您的静态页面(例如 test.html)放在 resources/static 下。 (Add a Home Page section 下的官方 Spring 演示页面中有一个示例,其中包含有关适当文件夹的简短说明)

2) 在

之后使用@Controller注解class指定映射规则

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class GreetingController {

        @GetMapping(value = "/ownPage")
        public String index() {
                return "test.html";
        }

}

3) 导航到 yourURL\ownPage@GetMapping 内指定的任何路径值。这将 return test.html 页面

感谢 cfrick 提供线索。更改了 vaadin 的 servlet url 映射并将 index.html 留在原处。

对于遇到同样问题的人,一切都在这里:Changing vaadin servlet url mapping