2012-03-16 46 views
2

我在尝试使用了Servlet 3.0编程的方式来注册使用的Jetty Maven插件运行servlet得到一个Spring 3.1框架的web应用的问题。码头8 Maven插件码头:运行战争没有检测WebApplicationInitializer

这里是我的Maven插件定义(指定具有默认的servlet映射删除一个覆盖webdefault.xml):

<plugin> 
    <groupId>org.mortbay.jetty</groupId> 
    <artifactId>jetty-maven-plugin</artifactId> 
    <version>8.1.1.v20120215</version> 
    <configuration> 
     <systemProperties> 
     <systemProperty> 
      <name>DEBUG</name> 
      <value>TRUE</value> 
     </systemProperty> 
     </systemProperties> 
     <scanIntervalSeconds>0</scanIntervalSeconds> 
     <webAppConfig> 
     <defaultsDescriptor>src/main/resources/webdefault.xml</defaultsDescriptor> 
     </webAppConfig> 
     <stopPort>9966</stopPort> 
     <stopKey>foo</stopKey> 
    </configuration> 
    </plugin> 

这是我切下来的webapp:

public class GcpWebApplicationInitializer implements WebApplicationInitializer { 
    public void onStartup(ServletContext servletContext) throws ServletException { 
     AnnotationConfigWebApplicationContext root = 
      new AnnotationConfigWebApplicationContext(); 
     root.scan(); 
     servletContext.addListener(new ContextLoaderListener(root)); 
     ServletRegistration.Dynamic servlet = servletContext.addServlet("TESTSERVLET", new DispatcherServlet(root)); 
     servlet.setLoadOnStartup(1); 
     servlet.addMapping("/"); 
    } 
} 

的commannd线我用这个运行起来的是:

mvn -U clean package jetty:run-war 

用下面的输出(只是run-war par T):

[INFO] Configuring Jetty for project: GCP Jetty 
[INFO] Context path =/
[INFO] Tmp directory = /Users/srowatt/dev/svn/prototypes/gcp-jetty/trunk/target/tmp 
[INFO] Web defaults = src/main/resources/webdefault.xml 
[INFO] Web overrides = none 
2012-03-16 17:09:25.668:INFO:oejs.Server:jetty-8.1.1.v20120215 
2012-03-16 17:09:25.691:INFO:oejw.WebInfConfiguration:Extract jar:file:/Users/srowatt/dev/svn/prototypes/gcp-jetty/trunk/target/gcp-jetty-0.0.1-SNAPSHOT.war!/ to /Users/srowatt/dev/svn/prototypes/gcp-jetty/trunk/target/gcp-jetty-0.0.1-SNAPSHOT 
2012-03-16 17:09:27.068:INFO:oejpw.PlusConfiguration:No Transaction manager found - if your webapp requires one, please configure one. 
2012-03-16 17:09:30.925:INFO:/:No Spring WebApplicationInitializer types detected on classpath 
2012-03-16 17:09:31.186:INFO:oejsh.ContextHandler:started o.m.j.p.JettyWebAppContext{/,file:/Users/srowatt/dev/svn/prototypes/gcp-jetty/trunk/target/gcp-jetty-0.0.1-SNAPSHOT/},/Users/srowatt/dev/svn/prototypes/gcp-jetty/trunk/target/gcp-jetty-0.0.1-SNAPSHOT.war 
2012-03-16 17:09:31.186:INFO:oejsh.ContextHandler:started o.m.j.p.JettyWebAppContext{/,file:/Users/srowatt/dev/svn/prototypes/gcp-jetty/trunk/target/gcp-jetty-0.0.1-SNAPSHOT/},/Users/srowatt/dev/svn/prototypes/gcp-jetty/trunk/target/gcp-jetty-0.0.1-SNAPSHOT.war 
2012-03-16 17:09:31.186:INFO:oejsh.ContextHandler:started o.m.j.p.JettyWebAppContext{/,file:/Users/srowatt/dev/svn/prototypes/gcp-jetty/trunk/target/gcp-jetty-0.0.1-SNAPSHOT/},/Users/srowatt/dev/svn/prototypes/gcp-jetty/trunk/target/gcp-jetty-0.0.1-SNAPSHOT.war 
2012-03-16 17:09:31.233:INFO:oejs.AbstractConnector:Started [email protected]:8080 
[INFO] Started Jetty Server 

正如你可以看到它检测到春天的servlet SpringServletContainerInitializer但这个servlet未检测到GcpWebApplicationInitializer。但是,如果我拿起war文件并手动将其置于独立的Jetty下,它将检测到GcpWebApplicationInitializer。

Shanes-MacBook-Pro:bin srowatt$ ./jetty.sh run 
Running Jetty: 
2012-03-16 17:26:21.051:INFO::Redirecting stderr/stdout to /Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/logs/2012_03_16.stderrout.log 
2012-03-16 17:26:21.353:INFO:oejs.Server:jetty-8.1.1.v20120215 
2012-03-16 17:26:21.371:INFO:oejdp.ScanningAppProvider:Deployment monitor /Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps at interval 1 
2012-03-16 17:26:21.379:INFO:oejd.DeploymentManager:Deployable added: /Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/cometd.war 
2012-03-16 17:26:21.452:INFO:oejw.WebInfConfiguration:Extract jar:file:/Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/cometd.war!/ to /private/var/folders/k3/bb7sgd616rdbwj9n0xl2k92m0000gq/T/jetty-0.0.0.0-8080-cometd.war-_cometd-any-/webapp 
2012-03-16 17:26:23.976:WARN:oejj.ObjectMBean:No mbean getter or setters found for maxCookieAge in class org.eclipse.jetty.server.session.HashSessionManager 
2012-03-16 17:26:23.976:WARN:oejj.ObjectMBean:No mbean getter or setters found for sessionPath in class org.eclipse.jetty.server.session.HashSessionManager 
2012-03-16 17:26:24.215:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/cometd,file:/private/var/folders/k3/bb7sgd616rdbwj9n0xl2k92m0000gq/T/jetty-0.0.0.0-8080-cometd.war-_cometd-any-/webapp/},/Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/cometd.war 
2012-03-16 17:26:24.216:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/cometd,file:/private/var/folders/k3/bb7sgd616rdbwj9n0xl2k92m0000gq/T/jetty-0.0.0.0-8080-cometd.war-_cometd-any-/webapp/},/Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/cometd.war 
2012-03-16 17:26:24.216:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/cometd,file:/private/var/folders/k3/bb7sgd616rdbwj9n0xl2k92m0000gq/T/jetty-0.0.0.0-8080-cometd.war-_cometd-any-/webapp/},/Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/cometd.war 
2012-03-16 17:26:24.466:INFO:oejd.DeploymentManager:Deployable added: /Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/root 
2012-03-16 17:26:24.576:WARN:oejj.ObjectMBean:No mbean getter or setters found for maxCookieAge in class org.eclipse.jetty.server.session.HashSessionManager 
2012-03-16 17:26:24.576:WARN:oejj.ObjectMBean:No mbean getter or setters found for sessionPath in class org.eclipse.jetty.server.session.HashSessionManager 
2012-03-16 17:26:24.581:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/,file:/Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/root/},/Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/root 
2012-03-16 17:26:24.581:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/,file:/Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/root/},/Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/root 
2012-03-16 17:26:24.581:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/,file:/Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/root/},/Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/root 
2012-03-16 17:26:24.583:INFO:oejd.DeploymentManager:Deployable added: /Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/gcp-jetty-0.0.1-SNAPSHOT.war 
2012-03-16 17:26:24.602:INFO:oejw.WebInfConfiguration:Extract jar:file:/Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/gcp-jetty-0.0.1-SNAPSHOT.war!/ to /private/var/folders/k3/bb7sgd616rdbwj9n0xl2k92m0000gq/T/jetty-0.0.0.0-8080-gcp-jetty-0.0.1-SNAPSHOT.war-_gcp-jetty-0.0.1-SNAPSHOT-any-/webapp 
2012-03-16 17:26:29.305:WARN:oejj.ObjectMBean:No mbean getter or setters found for maxCookieAge in class org.eclipse.jetty.server.session.HashSessionManager 
2012-03-16 17:26:29.305:WARN:oejj.ObjectMBean:No mbean getter or setters found for sessionPath in class org.eclipse.jetty.server.session.HashSessionManager 
2012-03-16 17:26:29.314:INFO:g0.1-SNAPSHOT:Spring WebApplicationInitializers detected on classpath: [[email protected]] 
2012-03-16 17:26:30.362:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/gcp-jetty-0.0.1-SNAPSHOT,file:/private/var/folders/k3/bb7sgd616rdbwj9n0xl2k92m0000gq/T/jetty-0.0.0.0-8080-gcp-jetty-0.0.1-SNAPSHOT.war-_gcp-jetty-0.0.1-SNAPSHOT-any-/webapp/},/Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/gcp-jetty-0.0.1-SNAPSHOT.war 
2012-03-16 17:26:30.363:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/gcp-jetty-0.0.1-SNAPSHOT,file:/private/var/folders/k3/bb7sgd616rdbwj9n0xl2k92m0000gq/T/jetty-0.0.0.0-8080-gcp-jetty-0.0.1-SNAPSHOT.war-_gcp-jetty-0.0.1-SNAPSHOT-any-/webapp/},/Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/gcp-jetty-0.0.1-SNAPSHOT.war 
2012-03-16 17:26:30.363:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/gcp-jetty-0.0.1-SNAPSHOT,file:/private/var/folders/k3/bb7sgd616rdbwj9n0xl2k92m0000gq/T/jetty-0.0.0.0-8080-gcp-jetty-0.0.1-SNAPSHOT.war-_gcp-jetty-0.0.1-SNAPSHOT-any-/webapp/},/Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/gcp-jetty-0.0.1-SNAPSHOT.war 
2012-03-16 17:26:30.363:INFO:g0.1-SNAPSHOT:Initializing Spring root WebApplicationContext 
2012-03-16 17:26:30.495:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/gcp-jetty-0.0.1-SNAPSHOT,file:/private/var/folders/k3/bb7sgd616rdbwj9n0xl2k92m0000gq/T/jetty-0.0.0.0-8080-gcp-jetty-0.0.1-SNAPSHOT.war-_gcp-jetty-0.0.1-SNAPSHOT-any-/webapp/},/Users/srowatt/dev/tools/jetty-hightide-8.1.1.v20120215/webapps/gcp-jetty-0.0.1-SNAPSHOT.war 
2012-03-16 17:26:30.498:INFO:g0.1-SNAPSHOT:Initializing Spring FrameworkServlet 'TESTSERVLET' 

另外,如果我用 MVN -U清洁套装码头:运行 那么它也将检测GcpWebApplicationInitializer,因为它应该。

那么,为什么码头:运行战争行为不如我所料?最初我以为这是造成这个问题的码头插件,但现在我认为它更像是Spring问题或类路径问题。

+1

我试着在我的IDE来调试这一点,它与上SpringServletContainerInitializer.onStartup断点()调用码头:运行在经过与它在我的servlet类设置正确的webAppInitializerClasses。码头:运行战争在同一断点没有webAppInitializerClasses在通过它的码头调用此方法,因此它肯定看起来像Jetty是不处理的@HandlesTypes(WebApplicationInitializer.class)注释。 – 2012-03-17 04:19:47

+0

同样在我的webdefault.xml中,我也尝试将metadata-complete设置为false - 这没有帮助。我也尝试将web_app_2_5.xsd提升到web_app_3_0.xsd,但仍然没有帮助。 – 2012-03-17 04:23:16

回答

1

我们正在使用类似的设置与弹簧3.1 &码头8.我们的配置是:

 <plugin> 
      <groupId>org.mortbay.jetty</groupId> 
      <artifactId>jetty-maven-plugin</artifactId> 
      <version>${jetty.version}</version> 
      <configuration> 
       <webApp> 
        <contextPath>/</contextPath> 
       </webApp> 
       <jettyConfig>src/main/resources/jetty.xml</jettyConfig> 
       <systemProperties> 
        <systemProperty> 
         <name>log4j.configuration</name> 
         <value>file://${project.basedir}/src/main/conf/target/generated-resources/log4j.xml</value> 
        </systemProperty> 
        <systemProperty> 
         <name>env</name> 
         <value>${env}</value> 
        </systemProperty> 
       </systemProperties> 
       <stopKey>I_CANT_STAND_IT_ANYMORE</stopKey> 
       <stopPort>54124</stopPort> 
      </configuration> 
     </plugin> 

你需要行家3.x中,与Maven 2你会是不是servlet码头结束3.0兼容。

+4

伟大的stopKey! ;-) – stefanglase 2012-04-25 15:16:14

相关问题