Spring jetty-maven-plugin 中未调用映射的 servlet
Spring mapped servlet not called in jetty-maven-plugin
我 从 maven-jetty-plugin
到 jetty-maven-plugin
。当我使用 jetty:run
启动码头时,我可以看到上下文已部署,正在初始化应用程序但未找到 servlet。它与 maven-jetty-plugin
.
一起正常工作
Java
@RequestMapping(value = "/handshake", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
public void performHandShake(@org.springframework.web.bind.annotation.RequestBody String requestData, HttpServletResponse response) throws IOException {
web.xml
<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>
行家
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${maven-jetty-plugin.version}</version>
<configuration>
<webApp>
<contextPath>pos-json</contextPath>
</webApp>
<scanIntervalSeconds>0</scanIntervalSeconds>
No context on this server matched or handled this request.
Contexts known to this server are:
pos-json ---> o.e.j.m.p.JettyWebAppContext@6c6366cf{pos-json,file:///C:/dev/projekty/pos-backend/src/main/webapp/,AVAILABLE}{file:///C:/dev/projekty/pos-backend/src/main/webapp/}
浏览器位于 http://localhost:8080/pos-json/handshake
HTTP ERROR 404
Problem accessing /pos-json/handshake. Reason: Not Found
码头
[INFO] Classes = C:\dev\projekty\pos-backend\target\classes
[INFO] Context path = pos-json
[INFO] Tmp directory = C:\dev\projekty\pos-backend\target\tmp
[INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml
[INFO] Web overrides = none
[INFO] web.xml file = file:///C:/dev/projekty/pos-backend/src/main/webapp/WEB-INF/web.xml
[INFO] Webapp directory = C:\dev\projekty\pos-backend\src\main\webapp
2017-10-20 14:21:17.907:INFO:oejs.Server:main: jetty-9.4.7.v20170914
2017-10-20 14:21:23.050:INFO:oeja.AnnotationConfiguration:main: Scanning elapsed time=4520ms
2017-10-20 14:21:23.486:INFO:oejs.session:main: DefaultSessionIdManager workerName=node0
2017-10-20 14:21:23.486:INFO:oejs.session:main: No SessionScavenger set, using defaults
2017-10-20 14:21:23.490:INFO:oejs.session:main: Scavenging every 660000ms
2017-10-20 14:21:24.498:INFO:oejshC.pos_json:main: Initializing Spring FrameworkServlet 'dispatcher'
2017-10-20 14:21:39,828 INFO [main] o.s.w.s.m.m.a.RequestMappingHandlerMapping Mapped "{[/handshake],methods=[POST],produces=[application/json;charset=UTF-8]}" onto public void pos.backend.device.controller.DeviceJsonController.performHandShake(java.lang.String,javax.servlet.http.HttpServletResponse) throws java.io.IOException
2017-10-20 14:21:40,167 INFO [main] o.s.w.s.m.m.a.RequestMappingHandlerAdapter Looking for @ControllerAdvice: WebApplicationContext for namespace 'dispatcher-servlet': startup date [Fri Oct 20 14:21:24 CEST 2017]; root of context hierarchy
2017-10-20 14:21:40.783:INFO:oejsh.ContextHandler:main: Started o.e.j.m.p.JettyWebAppContext@6c6366cf{pos-json,file:///C:/dev/projekty/pos-backend/src/main/webapp/,AVAILABLE}{file:///C:/dev/projekty/pos-backend/src/main/webapp/}
2017-10-20 14:21:41.017:INFO:oejs.AbstractConnector:main: Started ServerConnector@179efe9a{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
从 documentation 关于 jetty-maven-plugin
的配置看来 contextPath
他们建议你 可能 ( 非常模糊我必须承认) 需要添加前导正斜杠 "/"
,这样你的 Maven 插件定义应该是:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${maven-jetty-plugin.version}</version>
<configuration>
<webApp>
<contextPath>/pos-json</contextPath>
</webApp>
<scanIntervalSeconds>0</scanIntervalSeconds>
</configuration>
</plugin>
希望对您有所帮助!
我 maven-jetty-plugin
到 jetty-maven-plugin
。当我使用 jetty:run
启动码头时,我可以看到上下文已部署,正在初始化应用程序但未找到 servlet。它与 maven-jetty-plugin
.
Java
@RequestMapping(value = "/handshake", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
public void performHandShake(@org.springframework.web.bind.annotation.RequestBody String requestData, HttpServletResponse response) throws IOException {
web.xml
<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>
行家
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${maven-jetty-plugin.version}</version>
<configuration>
<webApp>
<contextPath>pos-json</contextPath>
</webApp>
<scanIntervalSeconds>0</scanIntervalSeconds>
No context on this server matched or handled this request.
Contexts known to this server are:
pos-json ---> o.e.j.m.p.JettyWebAppContext@6c6366cf{pos-json,file:///C:/dev/projekty/pos-backend/src/main/webapp/,AVAILABLE}{file:///C:/dev/projekty/pos-backend/src/main/webapp/}
浏览器位于 http://localhost:8080/pos-json/handshake
HTTP ERROR 404
Problem accessing /pos-json/handshake. Reason: Not Found
码头
[INFO] Classes = C:\dev\projekty\pos-backend\target\classes
[INFO] Context path = pos-json
[INFO] Tmp directory = C:\dev\projekty\pos-backend\target\tmp
[INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml
[INFO] Web overrides = none
[INFO] web.xml file = file:///C:/dev/projekty/pos-backend/src/main/webapp/WEB-INF/web.xml
[INFO] Webapp directory = C:\dev\projekty\pos-backend\src\main\webapp
2017-10-20 14:21:17.907:INFO:oejs.Server:main: jetty-9.4.7.v20170914
2017-10-20 14:21:23.050:INFO:oeja.AnnotationConfiguration:main: Scanning elapsed time=4520ms
2017-10-20 14:21:23.486:INFO:oejs.session:main: DefaultSessionIdManager workerName=node0
2017-10-20 14:21:23.486:INFO:oejs.session:main: No SessionScavenger set, using defaults
2017-10-20 14:21:23.490:INFO:oejs.session:main: Scavenging every 660000ms
2017-10-20 14:21:24.498:INFO:oejshC.pos_json:main: Initializing Spring FrameworkServlet 'dispatcher'
2017-10-20 14:21:39,828 INFO [main] o.s.w.s.m.m.a.RequestMappingHandlerMapping Mapped "{[/handshake],methods=[POST],produces=[application/json;charset=UTF-8]}" onto public void pos.backend.device.controller.DeviceJsonController.performHandShake(java.lang.String,javax.servlet.http.HttpServletResponse) throws java.io.IOException
2017-10-20 14:21:40,167 INFO [main] o.s.w.s.m.m.a.RequestMappingHandlerAdapter Looking for @ControllerAdvice: WebApplicationContext for namespace 'dispatcher-servlet': startup date [Fri Oct 20 14:21:24 CEST 2017]; root of context hierarchy
2017-10-20 14:21:40.783:INFO:oejsh.ContextHandler:main: Started o.e.j.m.p.JettyWebAppContext@6c6366cf{pos-json,file:///C:/dev/projekty/pos-backend/src/main/webapp/,AVAILABLE}{file:///C:/dev/projekty/pos-backend/src/main/webapp/}
2017-10-20 14:21:41.017:INFO:oejs.AbstractConnector:main: Started ServerConnector@179efe9a{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
从 documentation 关于 jetty-maven-plugin
的配置看来 contextPath
他们建议你 可能 ( 非常模糊我必须承认) 需要添加前导正斜杠 "/"
,这样你的 Maven 插件定义应该是:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${maven-jetty-plugin.version}</version>
<configuration>
<webApp>
<contextPath>/pos-json</contextPath>
</webApp>
<scanIntervalSeconds>0</scanIntervalSeconds>
</configuration>
</plugin>
希望对您有所帮助!