GWT spring-boot应用程序:servlet初始化

时间:2017-06-21 10:03:14

标签: spring-boot gwt

我有一个GWT应用程序(gwt 2.8),我想添加Spring-Boot依赖项(1.5.3.RELEASE)。我想要一个独立的可执行战争应用程序

这是我的web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
              http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5"
         xmlns="http://java.sun.com/xml/ns/javaee">

    <init-param>
      <param-name>contextClass</param-name>
      <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
    </init-param>

    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>com.mycompany.fonems.webapp.server.FonemsWebappApplication</param-value>
    </init-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- Servlets -->
    <servlet>
        <servlet-name>messageServlet</servlet-name>
        <servlet-class>com.mycompany.fonems.webapp.server.FONEMSWebMessageServiceImpl</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>messageServlet</servlet-name>
        <url-pattern>/fonemswebapp/FONEMSWebMessageService.rpc</url-pattern>
    </servlet-mapping>

    <servlet>
        <servlet-name>securityServlet</servlet-name>
        <servlet-class>com.mycompany.fonems.webapp.server.FONEMSWebSecurityServiceImpl</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>securityServlet</servlet-name>
        <url-pattern>/fonemswebapp/FONEMSWebSecurityService.rpc</url-pattern>
    </servlet-mapping>

    <servlet>
        <servlet-name>loginServlet</servlet-name>
        <servlet-class>com.mycompany.fonems.webapp.server.LoginServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>loginServlet</servlet-name>
        <url-pattern>/login</url-pattern>
    </servlet-mapping>

    <filter>
        <filter-name>gwtCacheControlFilter</filter-name>
        <filter-class>com.mycompany.fonems.webapp.server.GWTCacheControlFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>gwtCacheControlFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!-- Default page to serve -->
    <welcome-file-list>
        <welcome-file>Fonemswebapp.html</welcome-file>
    </welcome-file-list>
</web-app>

其中FonemsWebappApplication是我的spring-boot入口点类。

package com.mycompany.fonems.webapp.server;

import java.net.InetAddress;
import java.net.UnknownHostException;

import javax.inject.Inject;

import lombok.extern.slf4j.Slf4j;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

@Slf4j
@Configuration
@ComponentScan(basePackages = { "com.mycompany.fonems" })
@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class,
        ValidationAutoConfiguration.class })
public class FonemsWebappApplication {

    @Inject
    private Environment env;

    public static void main(String[] args) throws UnknownHostException {
        log.info("-------------------------------\tApplication is starting ...");

        SpringApplicationBuilder app = new SpringApplicationBuilder(FonemsWebappApplication.class);
        Environment env = app.run(args).getEnvironment();
        String portNumber = env.getProperty("server.port");
        log.info("\n----------------------------------------------------------\n\t"
                + "Application '{}' is running! Access URLs:\n\t" + "Local: \t\thttp://127.0.0.1:{}\n\t"
                + "External: \thttp://{}:{}\n----------------------------------------------------------",
                env.getProperty("spring.application.name"), portNumber, InetAddress.getLocalHost().getHostAddress(), portNumber);

        log.info("-------------------------------\tApplication is running");

    }
}

我启动了我的应用程序。它似乎从没有错误开始。尽管如此,在我的网络浏览器中,我有这样的错误:
访问/fonemswebapp/FONEMSWebMessageService.rpc 时出现问题 找不到路径

这里有日志:

[           main] o.s.w.s.resource.ResourceUrlProvider     : Looking for resource handler mappings
[           main] o.s.w.s.resource.ResourceUrlProvider     : Found resource handler mapping: URL pattern="/**/favicon.ico", locations=[ServletContext resource [/
], class path resource [META-INF/resources/], class path resource [resources/], class path resource [static/], class path resource [public/], class path resource []], resolvers=[org.springframework.we
b.servlet.resource.PathResourceResolver@7de5871d]
[           main] o.s.w.s.resource.ResourceUrlProvider     : Found resource handler mapping: URL pattern="/webjars/**", locations=[class path resource [META-INF/
resources/webjars/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@49d42faf]
[           main] o.s.w.s.resource.ResourceUrlProvider     : Found resource handler mapping: URL pattern="/**", locations=[ServletContext resource [/], class pat
h resource [META-INF/resources/], class path resource [resources/], class path resource [static/], class path resource [public/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResol
ver@4948daec]
[           main] o.s.web.servlet.DispatcherServlet        : Initializing servlet 'dispatcherServlet'
[           main] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
[           main] o.s.web.servlet.DispatcherServlet        : Using MultipartResolver [org.springframework.web.multipart.support.StandardServletMultipartResolver@
709d86a2]
[           main] o.s.web.servlet.DispatcherServlet        : Unable to locate LocaleResolver with name 'localeResolver': using default [org.springframework.web.s
ervlet.i18n.AcceptHeaderLocaleResolver@2e1add6f]
[           main] o.s.web.servlet.DispatcherServlet        : Unable to locate ThemeResolver with name 'themeResolver': using default [org.springframework.web.ser
vlet.theme.FixedThemeResolver@46702c26]
[           main] o.s.web.servlet.DispatcherServlet        : Unable to locate RequestToViewNameTranslator with name 'viewNameTranslator': using default [org.spri
ngframework.web.servlet.view.DefaultRequestToViewNameTranslator@2e3cd732]
[           main] o.s.web.servlet.DispatcherServlet        : Unable to locate FlashMapManager with name 'flashMapManager': using default [org.springframework.web
.servlet.support.SessionFlashMapManager@7f6b57f2]
[           main] o.s.web.servlet.DispatcherServlet        : Published WebApplicationContext of servlet 'dispatcherServlet' as ServletContext attribute with name
 [org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcherServlet]
[           main] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 31 ms
[           main] o.s.web.servlet.DispatcherServlet        : Servlet 'dispatcherServlet' configured successfully
[           main] .s.b.c.e.j.JettyEmbeddedServletContainer : Jetty started on port(s) 8088 (http/1.1)
[           main] o.s.w.c.s.StandardServletEnvironment     : Adding [server.ports] PropertySource with highest search precedence

[           main] c.n.f.w.server.FonemsWebappApplication   : Started FonemsWebappApplication in 7.634 seconds (JVM running for 8.248)
[           main] c.n.f.w.server.FonemsWebappApplication   : 
----------------------------------------------------------
    Application 'fonems-webapp-refonte' is running! Access URLs:
    Local:      http://127.0.0.1:8088
    External:   http://10.20.146.96:8088
----------------------------------------------------------
[           main] c.n.f.w.server.FonemsWebappApplication   : -------------------------------    Application is running

<< Then I launch this URL: http://127.0.0.1:8088/Fonemswebapp.html in my web broser>>

o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/fonemswebapp/fonemsweba
pp.nocache.js]
s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /fonemswebapp/fonemswebapp.nocache.js
s.w.s.m.m.a.RequestMappingHandlerMapping : Did not find handler method for [/fonemswebapp/fonemswebapp.nocache.js]
o.s.w.s.handler.SimpleUrlHandlerMapping  : Matching patterns for request [/fonemswebapp/fonemswebapp.nocache.js] are [/**]
o.s.w.s.handler.SimpleUrlHandlerMapping  : URI Template variables for request [/fonemswebapp/fonemswebapp.nocache.js] are {}
o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapping [/fonemswebapp/fonemswebapp.nocache.js] to HandlerExecutionChain with handler [ResourceHttpR
equestHandler [locations=[ServletContext resource [/], class path resource [META-INF/resources/], class path resource [resources/], class path resource [static/], class path resource [public/]], resol
vers=[org.springframework.web.servlet.resource.PathResourceResolver@4948daec]]] and 1 interceptor
o.s.web.servlet.DispatcherServlet        : Last-Modified value for [/fonemswebapp/fonemswebapp.nocache.js] is: -1
o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/error]
s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /error
s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method [public org.springframework.http.ResponseEntity<java.util.Map<java.lang.Str
ing, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)]
o.s.web.servlet.DispatcherServlet        : Last-Modified value for [/error] is: -1
o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Written [{timestamp=Fri Jun 16 11:02:10 CEST 2017, status=404, error=Not Found, message=Not Found, p
ath=/fonemswebapp/fonemswebapp.nocache.js}] as "application/json" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@6b09ce57]
o.s.web.servlet.DispatcherServlet        : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapt
er completed request handling
o.s.web.servlet.DispatcherServlet        : Successfully completed request
o.s.web.servlet.DispatcherServlet        : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapt
er completed request handling
o.s.web.servlet.DispatcherServlet        : Successfully completed request
o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/fonemswebapp/fonemsweba
pp.nocache.js]
s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /fonemswebapp/fonemswebapp.nocache.js
s.w.s.m.m.a.RequestMappingHandlerMapping : Did not find handler method for [/fonemswebapp/fonemswebapp.nocache.js]
o.s.w.s.handler.SimpleUrlHandlerMapping  : Matching patterns for request [/fonemswebapp/fonemswebapp.nocache.js] are [/**]
o.s.w.s.handler.SimpleUrlHandlerMapping  : URI Template variables for request [/fonemswebapp/fonemswebapp.nocache.js] are {}
o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapping [/fonemswebapp/fonemswebapp.nocache.js] to HandlerExecutionChain with handler [ResourceHttpR
equestHandler [locations=[ServletContext resource [/], class path resource [META-INF/resources/], class path resource [resources/], class path resource [static/], class path resource [public/]], resol
vers=[org.springframework.web.servlet.resource.PathResourceResolver@4948daec]]] and 1 interceptor
o.s.web.servlet.DispatcherServlet        : Last-Modified value for [/fonemswebapp/fonemswebapp.nocache.js] is: -1
o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/error]
s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /error
s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method [public org.springframework.http.ResponseEntity<java.util.Map<java.lang.Str
ing, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)]
o.s.web.servlet.DispatcherServlet        : Last-Modified value for [/error] is: -1
o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Written [{timestamp=Fri Jun 16 11:02:10 CEST 2017, status=404, error=Not Found, message=Not Found, p
ath=/fonemswebapp/fonemswebapp.nocache.js}] as "application/json" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@6b09ce57]
o.s.web.servlet.DispatcherServlet        : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapt
er completed request handling
o.s.web.servlet.DispatcherServlet        : Successfully completed request
o.s.web.servlet.DispatcherServlet        : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapt
er completed request handling
o.s.web.servlet.DispatcherServlet        : Successfully completed request

当我在firefox中启动网址时,会显示我的表单。当我点击搜索按钮时,我在更加明显的错误中出现此错误: HTTP错误404访问/fonemswebapp/FONEMSWebMessageService.rpc时出现问题。原因:未找到

这是我的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.mycompany.fonems</groupId>
        <artifactId>fonems-parent</artifactId>
        <version>0.0.140-SNAPSHOT</version>
        <relativePath>../fonems-parent/pom.xml</relativePath>
    </parent>

    <artifactId>fonems-webapp-refonte</artifactId>
    <packaging>war</packaging>
    <name>FONEMS WebApp</name>

  <properties>
    <!-- Setting maven.compiler.source to something different to 1.8
         needs that you configure the sourceLevel in gwt-maven-plugin since
         GWT compiler 2.8 requires 1.8 (see gwt-maven-plugin block below) -->
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>

    <!-- Don't let your Mac use a crazy non-standard encoding -->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  </properties>

  <dependencyManagement>
    <dependencies>
      <!-- ensure all GWT deps use the same version (unless overridden) -->
      <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt</artifactId>
        <version>${gwt.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>

  </dependencyManagement>

  <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-jetty</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    <dependency>
        <groupId>com.mycompany.fonems</groupId>
        <artifactId>fonems-fwk-server-common</artifactId>
            <version>${project.version}</version>
        <exclusions>
            <exclusion>
                <artifactId>xercesImpl</artifactId>
                <groupId>xerces</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>com.mycompany.fonems</groupId>
        <artifactId>fonems-refonte-dao</artifactId>
        <version>${project.version}</version>
        <exclusions>
            <exclusion>
                <artifactId>javax.el-api</artifactId>
                <groupId>javax.el</groupId>
            </exclusion>
            <exclusion>
                <artifactId>xercesImpl</artifactId>
                <groupId>xerces</groupId>
            </exclusion>
        </exclusions>
    </dependency>


    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-servlet</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-user</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-dev</artifactId>
      <scope>provided</scope>
    </dependency>


    <dependency>
        <groupId>com.smartgwt</groupId>
        <artifactId>smartgwt</artifactId>
        <version>${smartgwt.version}</version>
    </dependency>
    <dependency>
        <groupId>com.smartgwt</groupId>
        <artifactId>smartgwt-skins</artifactId>
        <version>${smartgwt.version}</version>
        <optional>true</optional>
    </dependency>
        <dependency>
            <groupId>mycompany.drh</groupId>
            <artifactId>newncauth</artifactId>
            <version>${mycompany.drh.version}</version>
        </dependency>
        <dependency>
            <groupId>mycompany.drh</groupId>
            <artifactId>mycompany.droits-habilitations.rmi</artifactId>
            <version>${mycompany.drh.rmi.version}</version>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>compile</scope>
        </dependency>
  </dependencies>

  <build>
    <!-- Output classes directly into the webapp, so that IDEs and "mvn process-classes" update them in DevMode -->
<!--     <outputDirectory>${project.build.directory}/src/main/webapp/WEB-INF/classes</outputDirectory> -->

    <plugins>

      <!-- GWT Maven Plugin-->
      <plugin>
        <groupId>net.ltgt.gwt.maven</groupId>
        <artifactId>gwt-maven-plugin</artifactId>
        <version>${gwt.maven.plugin.version}</version>
        <executions>
          <execution>
            <goals>
              <goal>import-sources</goal>
              <goal>compile</goal>
              <goal>import-test-sources</goal>
              <goal>test</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <moduleName>com.mycompany.fonems.webapp.Fonemswebapp</moduleName>
          <moduleShortName>Fonemswebapp</moduleShortName>
          <failOnError>true</failOnError>
          <!-- GWT compiler 2.8 requires 1.8, hence define sourceLevel here if you use
               a different source language for java compilation -->
          <sourceLevel>1.8</sourceLevel>
          <!-- Compiler configuration -->
          <compilerArgs>
            <!-- Ask GWT to create the Story of Your Compile (SOYC) (gwt:compile) -->
            <arg>-compileReport</arg>
            <arg>-XcompilerMetrics</arg>
          </compilerArgs>
          <!-- DevMode configuration -->
          <warDir>${project.build.directory}/${project.build.finalName}</warDir>
          <classpathScope>compile+runtime</classpathScope>
          <!-- URL(s) that should be opened by DevMode (gwt:devmode). -->
          <startupUrls>
            <startupUrl>Fonemswebapp.html</startupUrl>
          </startupUrls>

          <webappDirectory>${outputFolder}</webappDirectory>
        </configuration>

      </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <warSourceDirectory>target/www/</warSourceDirectory>
                    <packagingExcludes>WEB-INF/lib/tomcat-*.jar</packagingExcludes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <executable>false</executable>
                    <!-- Enable the line below to have remote debugging of your application on port 5005 <jvmArguments>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005</jvmArguments> -->
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptors>
                        <descriptor>assembly.xml</descriptor>
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

    </plugins>
  </build>
</project>

为什么在日志中我们看到ServletDispatcher出现了? 在我的应用程序中,我应该定义一个ServletDispatcher吗?如果是这种情况,如何定义我的5个web.xml servlet并过滤以考虑? 奇怪的是,当我从GWT开发模式(eclipse插件)启动它时,应用程序运行并正常响应。

谢谢

0 个答案:

没有答案