我在嘗試使用了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問題或類路徑問題。
我試着在我的IDE來調試這一點,它與上SpringServletContainerInitializer.onStartup斷點()調用碼頭:運行在經過與它在我的servlet類設置正確的webAppInitializerClasses。碼頭:運行戰爭在同一斷點沒有webAppInitializerClasses在通過它的碼頭調用此方法,因此它肯定看起來像Jetty是不處理的@HandlesTypes(WebApplicationInitializer.class)註釋。 – 2012-03-17 04:19:47
同樣在我的webdefault.xml中,我也嘗試將metadata-complete設置爲false - 這沒有幫助。我也嘗試將web_app_2_5.xsd提升到web_app_3_0.xsd,但仍然沒有幫助。 – 2012-03-17 04:23:16