开发者

Vaadin with maven project deploy in tomcat

开发者 https://www.devze.com 2023-02-03 08:30 出处:网络
I created a 开发者_如何学运维vaadin sample project using maven build tool.I used eclips IDE for this proejct and archetype is vaadin-archetype-clean,I was able to build the war file,After that I tried

I created a 开发者_如何学运维vaadin sample project using maven build tool.I used eclips IDE for this proejct and archetype is vaadin-archetype-clean,I was able to build the war file,After that I tried to deploy it in tomcat.What I did was copy the war(MyVaadinMavenProject-0.0.1-SNAPSHOT) file to /webapps folder in tomcat and restart the web server. Then I tried to access using "http://localhost:8080/MyVaadinMavenProject-0.0.1-SNAPSHOT" but that gives me and error telling

HTTP Status 404 - /MyVaadinMavenProject-0.0.1-SNAPSHOT

Can anyone tell me what is Where I made the mistake??

thanxx


In your web.xml you can write link, with will be used by your application, it mean http://localhost:{port}/your-application

<servlet>
        <servlet-name>your-application</servlet-name>
        <servlet-class>com.vaadin.terminal.gwt.server.ApplicationServlet</servlet-class>
        <init-param>
            <param-name>application</param-name>
            <param-value>package.YourApplication</param-value>
        </init-param>
        <init-param>
            <param-name>widgetset</param-name>
            <param-value>com.vaadin.terminal.gwt.DefaultWidgetSet</param-value>
        </init-param>
    </servlet>

<servlet-mapping>
        <servlet-name>your-application</servlet-name>
        <url-pattern>/your-application-link/*</url-pattern>
    </servlet-mapping>

It is one way, but if you use Spring in your project more likely use dispatcher servlet to init Vaadin application. In your web.xml file

<servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

Create file dispatcher-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="
             http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
    <bean id="applicationServlet" class="org.springframework.web.servlet.mvc.ServletWrappingController" p:servletClass="package.YourApplication">
        <property name="initParameters">
            <props>
                <prop key="application">package.YourApplication</prop>
                <prop key="widgetset">com.vaadin.terminal.gwt.DefaultWidgetSet</prop>
            </props>
        </property>
    </bean>
    <!-- Map URIs to web controllers -->
    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="urlMap">
            <map>
                <entry key="/" value-ref="redirectController" />
                <entry key="/favicon.ico" value-ref="applicationServlet" />
                <entry key="/VAADIN*/**" value-ref="applicationServlet" />
                <entry key="/UIDL*/**" value-ref="applicationServlet" />
                <entry key="/your-application" value-ref="applicationServlet" />
            </map>
        </property>
    </bean>
</beans>

Inside urlMap your can write with link are allowed to init. your vaadin application.

Create redirectController

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller("redirectController")
public class RedirectController {
    @RequestMapping
    protected ModelAndView handleRequestInternal() throws Exception {
        return new ModelAndView("redirectView");
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消