簡體   English   中英

Spring WebApplicationInitializer和Jetty 8.x.

[英]Spring WebApplicationInitializer and Jetty 8.x

我正在嘗試使用Maven在Jetty中部署應用程序:

我有這個插件配置如下:

<plugin>
  <groupId>org.mortbay.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <version>8.0.4.v20111024</version>
</plugin>

我有一個WebApplicationContextInitializer,我把它簡化為一個簡單的形式:

AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();

// Register and map the main dispatcher servlet
ServletRegistration.Dynamic dispatcher = container.addServlet("appServlet", new DispatcherServlet(dispatcherContext));
dispatcher.setLoadOnStartup(2);
dispatcher.addMapping("/site/*");

當我運行jetty時:從Spring Tool Suite中運行我無法訪問我的servlet。 啟動日志是:

    [INFO] Configuring Jetty for project: Test
    [INFO] webAppSourceDirectory C:\Users\Alex\Documents\spring\Test\src\main\webapp does not exist. Defaulting to C:\Users\Alex\Documents\spring\Test\src\main\webapp
    [INFO] Reload Mechanic: automatic
    [INFO] Classes = C:\Users\Alex\Documents\spring\Test\target\classes
    [INFO] Context path = /
    [INFO] Tmp directory = C:\Users\Alex\Documents\spring\Test\target\tmp
    [INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml
    [INFO] Web overrides =  none
    [INFO] web.xml file = null
    [INFO] Webapp directory = C:\Users\Alex\Documents\spring\Test\src\main\webapp
    2012-02-06 21:22:38.048:INFO:oejs.Server:jetty-8.0.4.v20111024
    2012-02-06 21:22:38.807:INFO:oejpw.PlusConfiguration:No Transaction manager found - if your webapp requires one, please configure one.
    2012-02-06 21:22:41.828:INFO:/:Spring WebApplicationInitializers detected on classpath: [org.test.application.config.TestWebApplicationInitializer@f946f9]
    2012-02-06 21:22:41.965:INFO:/:Initializing Spring FrameworkServlet 'appServlet'
    INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'appServlet': initialization started
    INFO : org.springframework.web.context.support.AnnotationConfigWebApplicationContext - Refreshing WebApplicationContext for namespace 'appServlet-servlet': startup date [Mon Feb 06 21:22:41 GMT 2012]; root of context hierarchy
    INFO : org.springframework.context.annotation.ClassPathBeanDefinitionScanner - JSR-330 'javax.inject.Named' annotation found and supported for component scanning
    INFO : org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
    INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@18b24cb: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; root of factory hierarchy
    INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'appServlet': initialization completed in 235 ms
    2012-02-06 21:22:42.344:INFO:oejsh.ContextHandler:started o.m.j.p.JettyWebAppContext{/,file:/C:/Users/Alex/Documents/spring/Test/src/main/webapp/},file:/C:/Users/Alex/Documents/spring/Test/src/main/webapp/
    2012-02-06 21:22:42.344:INFO:oejsh.ContextHandler:started o.m.j.p.JettyWebAppContext{/,file:/C:/Users/Alex/Documents/spring/Test/src/main/webapp/},file:/C:/Users/Alex/Documents/spring/Test/src/main/webapp/
    2012-02-06 21:22:42.345:INFO:oejsh.ContextHandler:started o.m.j.p.JettyWebAppContext{/,file:/C:/Users/Alex/Documents/spring/Test/src/main/webapp/},file:/C:/Users/Alex/Documents/spring/Test/src/main/webapp/
    2012-02-06 2012-02-06 21:22:42.352:INFO:oejs.AbstractConnector:Started SelectChannelConnector@0.0.0.0:8080 STARTING
    [INFO] Started Jetty Server

如果然后導航到http:// localhost:8080 /我得到默認的Jetty頁面,沒有列出上下文。

我已經嘗試將webdefaults.xml復制到我的項目中,如此處所述但這並沒有解決問題。 它只是刪除了默認的servlet頁面。

這在Tomcat中正確部署,所以我懷疑maven-jetty-plugin中存在問題。

有沒有人在這方面有經驗?

編輯:

所以我可以確認,如果我更改Jetty配置,以便在上下文/應用程序下部署應用程序,然后導航到http:// localhost:8080 / application / site /我得到404。

但是,調度程序servlet已記錄:

No mapping found for HTTP request with URI [/application/site/] in DispatcherServlet with name 'appServlet'

這表明我的控制器映射存在問題是否正確?

啟動日志顯示此映射已注冊:

Mapped "{[/],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String org.test.application.controller.HomeController.catchAll()

我錯過了什么?

似乎新的Jetty插件使用root“/”作為Web應用程序的根上下文,舊的如下所示:

contextPath可選。 您的webapp的上下文路徑。 默認情況下,它設置為項目的pom.xml。 您可以覆蓋它並將其設置為您喜歡的任何內容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM