HTTP 405,在基于SPRING-BOOT JSP的Web应用程序中嵌入VAADIN UI

HTTP 405,在基于SPRING-BOOT JSP的Web应用程序中嵌入VAADIN UI,spring,spring-security,spring-boot,vaadin,Spring,Spring Security,Spring Boot,Vaadin,我已经集成了Vaadin 7,将UI嵌入到基于Spring Boot的应用程序的一些JSP页面中,如Vaadin书中所述 尽管当我调用嵌入它的路径(通过SpringMVC控制器)时,名为“v-my-vaadin-UI”的UI被正确显示,但在与UI交互时,我得到了一个HTTP405错误 URL上出现错误: 似乎是因为在Spring引导中,默认情况下,所有控制器都只允许使用GET方法(正如所解释的,必须显式地允许POST) 已尝试在我的Spring Security配置中禁用CSRF并配置Vaad

我已经集成了Vaadin 7,将UI嵌入到基于Spring Boot的应用程序的一些JSP页面中,如Vaadin书中所述

尽管当我调用嵌入它的路径(通过SpringMVC控制器)时,名为“v-my-vaadin-UI”的UI被正确显示,但在与UI交互时,我得到了一个HTTP405错误

URL上出现错误:

似乎是因为在Spring引导中,默认情况下,所有控制器都只允许使用GET方法(正如所解释的,必须显式地允许POST)

已尝试在我的Spring Security配置中禁用CSRF并配置Vaadin相关路径:

http.authorizeRequests()
.antMatchers("/vaadinServlet/**", 
"/UIDL/**", 
"/v-my-vaadin-ui/UIDL/**", 
"/v-my-vaadin-ui/PUSH/**", 
"/HEARTBEAT/**", "/VAADIN/**").permitAll();
http.csrf().disable();
因为VAADIN集成不需要Spring管理的CSRF,但这并不能解决问题

VAADIN应用程序非常基本:

@SpringUI(path = "v-my-vaadin-ui")
public class MyVaadinUI extends UI {

    private static final long serialVersionUID = -8129815147461786549L;

    @Override
    protected void init(VaadinRequest vaadinRequest) {

        final TextField name = new TextField("Name");
        final Button greetButton = new Button("Greet");

        greetButton.addClickListener(new ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                Notification.show("Hi " + name.getValue(), 
                                  Notification.Type.HUMANIZED_MESSAGE);
            }
        });

        VerticalLayout vl = new VerticalLayout(name, greetButton);
        vl.setSpacing(true);
        setContent(vl);
    }

}
但点击Vaadin按钮,响应代码为405,具体例外情况如下:

.w.s.m.a.ResponseStatusExceptionResolver:从处理程序[ResourceHttpRequestHandler[locations=[ServletContext resource[/],类路径资源[META-INF/resources/],类路径资源[resources/],类路径资源[static/],类路径资源[public/],解析程序解析异常=[org.springframework.web.servlet.resource。PathResourceResolver@4a8756c3]]]:org.springframework.web.HttpRequestMethodNotSupportedException:不支持请求方法'POST'

不幸的是,我没有找到任何方法来为UI配置POST方法,就像为一个简单的控制器配置POST方法一样,即通过

@RequestMapping(method = {RequestMethod.GET, RequestMethod.POST})
因为此批注不能用于Vaadin UI

此外,如果我使用URL直接调用UI(即不通过Spring控制器):

用户界面显示和工作完美


知道是什么导致了这个问题吗?我如何允许POST方法?

你尝试过这个附加组件吗?

你尝试过这个附加组件吗?

解决了

该问题是由我在嵌入VAADIN应用程序时使用的JS脚本中出错引起的(我遵循了以下文档:),特别是“serviceUrl”参数的代码片段:

"serviceUrl": "helloworld/",
我已经理解为使用应用程序的名称设置,在我的例子中是“v-my-vaadin-ui”

但在我的例子中,正确的“serviceUrl”仍然是默认的一个“vaadinServlet/”,因此从:

"serviceUrl": "v-my-vaadin-ui/",

一切正常

下面是JSP标记的完整代码,用于嵌入适用于我的vaadin应用程序:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@tag description="ajax widget tag" pageEncoding="UTF-8"%>

<%@attribute name="v_app_url"%>

<%-- Javascript as described here: https://vaadin.com/docs/-/part/framework/advanced/advanced-embedding.html --%>

<div>

    <div id="${v_app_url}" class="v-app myvaadinui" >
       <div class="v-app-loading"></div>
       <noscript>
        You have to enable javascript in your browser to use an application built with Vaadin.
       </noscript>
    </div>

    <script type="text/javascript">//<![CDATA[
        if (!window.vaadin)
            alert("Failed to load the bootstrap JavaScript: vaadinBootstrap.js");

            /* The UI Configuration */
            vaadin.initApplication("${v_app_url}", {
                "browserDetailsUrl": "${v_app_url}/",
                "serviceUrl": "vaadinServlet/",
                "widgetset": "com.vaadin.DefaultWidgetSet",
                "theme": "valo",
                "versionInfo": {"vaadinVersion": "7.4.4"},
                "vaadinDir": "/VAADIN/",
                "heartbeatInterval": 300,
                "debug": false,
                "standalone": false,
                "authErrMsg": {
                    "message": "Take note of any unsaved data, "+
                               "and <u>click here<\/u> to continue.",
                    "caption": "Authentication problem"
                },
                "comErrMsg": {
                    "message": "Take note of any unsaved data, "+
                               "and <u>click here<\/u> to continue.",
                    "caption": "Communication problem"
                },
                "sessExpMsg": {
                    "message": "Take note of any unsaved data, "+
                               "and <u>click here<\/u> to continue.",
                    "caption": "Session Expired"
                }
            });//]] >
     </script>

</div>

您必须在浏览器中启用javascript才能使用使用Vaadin构建的应用程序。
//
已解决

该问题是由我在嵌入VAADIN应用程序时使用的JS脚本中出错引起的(我遵循了以下文档:),特别是“serviceUrl”参数的代码片段:

"serviceUrl": "helloworld/",
我已经理解为使用应用程序的名称设置,在我的例子中是“v-my-vaadin-ui”

但在我的例子中,正确的“serviceUrl”仍然是默认的一个“vaadinServlet/”,因此从:

"serviceUrl": "v-my-vaadin-ui/",

一切正常

下面是JSP标记的完整代码,用于嵌入适用于我的vaadin应用程序:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@tag description="ajax widget tag" pageEncoding="UTF-8"%>

<%@attribute name="v_app_url"%>

<%-- Javascript as described here: https://vaadin.com/docs/-/part/framework/advanced/advanced-embedding.html --%>

<div>

    <div id="${v_app_url}" class="v-app myvaadinui" >
       <div class="v-app-loading"></div>
       <noscript>
        You have to enable javascript in your browser to use an application built with Vaadin.
       </noscript>
    </div>

    <script type="text/javascript">//<![CDATA[
        if (!window.vaadin)
            alert("Failed to load the bootstrap JavaScript: vaadinBootstrap.js");

            /* The UI Configuration */
            vaadin.initApplication("${v_app_url}", {
                "browserDetailsUrl": "${v_app_url}/",
                "serviceUrl": "vaadinServlet/",
                "widgetset": "com.vaadin.DefaultWidgetSet",
                "theme": "valo",
                "versionInfo": {"vaadinVersion": "7.4.4"},
                "vaadinDir": "/VAADIN/",
                "heartbeatInterval": 300,
                "debug": false,
                "standalone": false,
                "authErrMsg": {
                    "message": "Take note of any unsaved data, "+
                               "and <u>click here<\/u> to continue.",
                    "caption": "Authentication problem"
                },
                "comErrMsg": {
                    "message": "Take note of any unsaved data, "+
                               "and <u>click here<\/u> to continue.",
                    "caption": "Communication problem"
                },
                "sessExpMsg": {
                    "message": "Take note of any unsaved data, "+
                               "and <u>click here<\/u> to continue.",
                    "caption": "Session Expired"
                }
            });//]] >
     </script>

</div>

您必须在浏览器中启用javascript才能使用使用Vaadin构建的应用程序。
//

能否请您详细说明嵌入UI所使用的URL结构?或者您正在学习的教程的链接?如果您的直接UI工作正常,那么嵌入失败的一个解释就是与相关链接混淆。对UI本身的调用基本上只会返回嵌入UI的html“全屏”。请详细说明嵌入UI所使用的URL结构?或指向您正在学习的教程的链接?如果您的直接UI正常工作,则嵌入失败的一个解释是与相关链接混淆。对UI的调用本身基本上没有其他作用,只会返回嵌入UI的html“全屏”.嗨,Alejandro,感谢您的回复,老实说,我不知道您的插件(我刚刚创建了一个自定义标记,它使用VAADIN文档中描述的JS嵌入UI)。我试图将其添加到maven pom.xml中,但得到以下异常:由以下原因引起:java.lang.ClassNotFoundException:com.vaadin.server.ServiceDestroyListener位于java.net.URLClassLoader$1.run(URLClassLoader.java:366)~[na:1.7.075][…]它与:vaadin-spring-boot-starter-1.0.0兼容?是的,它支持它。您可能缺少pom.xml中的vaadin bom配置:嗨,Alejandro,感谢您的回复,老实说,我不知道您的插件(我刚刚创建了一个自定义标记,使用vaadin文档中描述的JS嵌入UI)。我试图将其添加到maven pom.xml中,但得到以下异常:由以下原因引起:java.lang.ClassNotFoundException:com.vaadin.server.ServiceDestroyListener位于java.net.URLClassLoader$1.run(URLClassLoader.java:366)~[na:1.7.075][…]它与:vaadin-spring-boot-starter-1.0.0兼容?是的,它支持它。您的pom.xml中可能缺少vaadin bom配置: