vaadin.url映射前端资源



我正试图将我的vadin 23.2.17应用程序移动到不同的urlMapping。我正在使用Spring Boot安全性,一切似乎都运行良好,我按照文档进行了配置应用程序的示例。属性参数

vaadin。urlMapping =/vadin/*

应用程序在新的上下文中启动,我还在我的application类中注册了一个新的VaadinServlet,如下所示:

@Bean
public ServletRegistrationBean frontendServletBean() {
ServletRegistrationBean bean = new ServletRegistrationBean<>(new VaadinServlet() {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
if (!serveStaticOrWebJarRequest(req, resp)) {
resp.sendError(404);
}
}
}, "/vaadin/frontend/*");
bean.setLoadOnStartup(1);
return bean;
}

尽管如此,应用程序似乎无法从frontend/images目录读取静态内容。例如,在我的代码中:

Image image = new Image("images/company-logo.gif", "company-logo");
portalLogo.add(image); 

但是没有显示,因为没有找到。

有人能帮我吗?

谢谢朱塞佩。

一旦您将Vaadin移出根目录,您的工作就是为静态提供服务资源:

VaadinServlet处理静态资源请求,如果您已经映射了它到/*。如果没有,servlet容器将负责处理静态资源请求。


来源:https://vaadin.com/docs/v23/advanced/loading-resources/静态资源

由于您通常不想更改代码中的所有引用,使用SpringBoot最简单的方法是将资源放在:

src/main/resources/static/

。你的文件:

src/main/resources/static/images/company-logo.gif

最新更新