【问题标题】:How to build Spring boot project which includes vaadin routes and static html pages如何构建包含 vaadin 路由和静态 html 页面的 Spring Boot 项目
【发布时间】:2019-09-22 03:28:39
【问题描述】:

我正在使用spring bootvaadin 和一些静态 html 页面(如引导程序的 UI 框架)构建一个 Web 应用程序。

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

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

1) 如果我将 index.html 放在 webapp 文件夹中,则可以从 www.localhost:8080/ url 访问它,但随后我从 vaadin 收到错误消息:

后端不接受对 www.localhost:8080/ 的 POST 请求

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

2) 如果我添加一个@Route("") 类,那么index.html 是无法访问的,但是后端接受来自 vaadin 客户端的 POST 请求...

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

有什么想法吗?

【问题讨论】:

  • 您是否尝试过使用 vaadin.url-mapping 设置将您的 vaadin servlet 移开?

标签: java spring spring-boot vaadin vaadin-flow


【解决方案1】:

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

1) 将您的静态页面(例如,test.html)放在 resources/static 下。 (在Add a Home Page section 下有来自Spring 官方演示页面的示例,并简要说明了相应的文件夹)

2) 之后使用@Controller注解类指定映射规则


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 中指定的任何路径值。这将返回test.html 页面

【讨论】:

  • 这是一个解决方案,但我希望从 www.app.domain/ 访问我的索引页面
【解决方案2】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-20
    • 1970-01-01
    • 2011-10-24
    • 2011-08-03
    • 1970-01-01
    • 2015-10-30
    相关资源
    最近更新 更多