我有一个部署在码头9.4.12上的Java angular项目
这是我的web.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" 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_3_0.xsd"
version="3.0">
<display-name>Tourism Applicationwith Angular</display-name>
<description>
This is a simple web application with a source code organization
based on the recommendations of the Application Developer's Guide.
</description>
<display-name>Archetype Created Web Application</display-name>
<listener>
<listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
</listener>
<listener>
<listener-class>
org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
</listener-class>
</listener>
<resource-env-ref>
<description>Object factory for the CDI Bean Manager</description>
<resource-env-ref-name>BeanManager</resource-env-ref-name>
<resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
</resource-env-ref>
<servlet>
<servlet-name>Resteasy</servlet-name>
<servlet-class>
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>webservice.TourismWebService</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Resteasy</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>resteasy.injector.factory</param-name>
<param-value>org.jboss.resteasy.cdi.CdiInjectorFactory</param-value>
</context-param>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
这是我的网络服务
package webservice;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.jboss.resteasy.cdi.CdiInjectorFactory;
import org.slf4j.Logger;
import business.TourismBusinessService;
import dto.SearchPathDto;
import dto.TourismPathDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
@Path("/tourism")
@Api(value = "analyses", description = "search path by userId, location and max distance")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class TourismWebService extends Application {
@Inject
private Logger logger;
@Inject
private TourismBusinessService tourismBusinessService;
@GET
@Path("searchPath/{userId}/{longitude}/{latitude}/{distanceMax}")
@ApiOperation("Get analysis by Id")
@ApiResponse(code = 200, message = "OK")
public Response searchPath(@PathParam("userId") long userId,@PathParam("longitude") double longitude,@PathParam("latitude") double latitude,@PathParam("distanceMax") double distanceMax) {
SearchPathDto responseDto = new SearchPathDto();
//org.jboss.resteasy.cdi.CdiInjectorFactory test = new org.jboss.resteasy.cdi.CdiInjectorFactory();
List<TourismPathDto> tourismPathDtoList = new ArrayList<>();
TourismPathDto tourismPathDto1 = new TourismPathDto();
tourismPathDto1.setCategoryId(1);
tourismPathDto1.setDistance((double)100);
tourismPathDto1.setLongitude(2.3313926);
tourismPathDto1.setLatitude(48.873278);
tourismPathDto1.setRoot("root1");
tourismPathDto1.setLeaf("leaf1");
tourismPathDto1.setWeight((double)2);
tourismPathDto1.setMark((double)3);
tourismPathDtoList.add(tourismPathDto1);
TourismPathDto tourismPathDto2 = new TourismPathDto();
tourismPathDto2.setCategoryId(2);
tourismPathDto2.setDistance((double)200);
tourismPathDto2.setLongitude(2.3368291);
tourismPathDto2.setLatitude(48.8747394);
tourismPathDto2.setRoot("root2");
tourismPathDto2.setLeaf("leaf2");
tourismPathDto2.setWeight((double)3);
tourismPathDto2.setMark((double)4);
tourismPathDtoList.add(tourismPathDto2);
responseDto.setDistanceMax(distanceMax);
responseDto.setLatitude(latitude);
responseDto.setLongitude(longitude);
responseDto.setUserId(userId);
responseDto.setTourismPathDtoList(tourismPathDtoList);
//SearchPathDto responseDto = tourismBusinessService.getTourismPathList(userId, longitude, latitude, distanceMax);
if (responseDto == null)
throw new WebApplicationException(Response.Status.NOT_FOUND);
return Response.ok(responseDto).build();
}
}
我跑了码头:java -jar start.jar
但是当我尝试访问以下Web服务
http://localhost:8080/tourism-services/tourism/searchPath/1/2.3313926/48.873278/200
我有一个 HTTP错误404
问题访问/tourism-services/tourism/searchPath/1/2.3313926/48.873278/200。原因:
Not Found
错误
谢谢您的帮助
这是续篇…… 我修改的jetty.xml如下
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<!-- =============================================================== -->
<!-- Documentation of this file format can be found at: -->
<!-- https://www.eclipse.org/jetty/documentation/current/ -->
<!-- -->
<!-- Additional configuration files are available in $JETTY_HOME/etc -->
<!-- and can be mixed in. See start.ini file for the default -->
<!-- configuration files. -->
<!-- -->
<!-- For a description of the configuration mechanism, see the -->
<!-- output of: -->
<!-- java -jar start.jar -? -->
<!-- =============================================================== -->
<!-- =============================================================== -->
<!-- Configure a Jetty Server instance with an ID "Server" -->
<!-- Other configuration files may also configure the "Server" -->
<!-- ID, in which case they are adding configuration to the same -->
<!-- instance. If other configuration have a different ID, they -->
<!-- will create and configure another instance of Jetty. -->
<!-- Consult the javadoc of o.e.j.server.Server for all -->
<!-- configuration that may be set here. -->
<!-- =============================================================== -->
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Arg name="threadpool"><Ref refid="threadPool"/></Arg>
<!-- =========================================================== -->
<!-- Add shared Scheduler instance -->
<!-- =========================================================== -->
<Call name="addBean">
<Arg>
<New class="org.eclipse.jetty.util.thread.ScheduledExecutorScheduler"/>
</Arg>
</Call>
<Ref refid="DeploymentManager">
<Call name="addLifeCycleBinding">
<Arg>
<New
class="org.eclipse.jetty.cdi.servlet.WeldDeploymentBinding">
</New>
</Arg>
</Call>
</Ref>
<!-- =========================================================== -->
<!-- Http Configuration. -->
<!-- This is a common configuration instance used by all -->
<!-- connectors that can carry HTTP semantics (HTTP, HTTPS, etc.)-->
<!-- It configures the non wire protocol aspects of the HTTP -->
<!-- semantic. -->
<!-- -->
<!-- This configuration is only defined here and is used by -->
<!-- reference from other XML files such as jetty-http.xml, -->
<!-- jetty-https.xml and other configuration files which -->
<!-- instantiate the connectors. -->
<!-- -->
<!-- Consult the javadoc of o.e.j.server.HttpConfiguration -->
<!-- for all configuration that may be set here. -->
<!-- =========================================================== -->
<New id="httpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
<Set name="secureScheme"><Property name="jetty.httpConfig.secureScheme" default="https" /></Set>
<Set name="securePort"><Property name="jetty.httpConfig.securePort" deprecated="jetty.secure.port" default="8443" /></Set>
<Set name="outputBufferSize"><Property name="jetty.httpConfig.outputBufferSize" deprecated="jetty.output.buffer.size" default="32768" /></Set>
<Set name="outputAggregationSize"><Property name="jetty.httpConfig.outputAggregationSize" deprecated="jetty.output.aggregation.size" default="8192" /></Set>
<Set name="requestHeaderSize"><Property name="jetty.httpConfig.requestHeaderSize" deprecated="jetty.request.header.size" default="8192" /></Set>
<Set name="responseHeaderSize"><Property name="jetty.httpConfig.responseHeaderSize" deprecated="jetty.response.header.size" default="8192" /></Set>
<Set name="sendServerVersion"><Property name="jetty.httpConfig.sendServerVersion" deprecated="jetty.send.server.version" default="true" /></Set>
<Set name="sendDateHeader"><Property name="jetty.httpConfig.sendDateHeader" deprecated="jetty.send.date.header" default="false" /></Set>
<Set name="headerCacheSize"><Property name="jetty.httpConfig.headerCacheSize" default="4096" /></Set>
<Set name="delayDispatchUntilContent"><Property name="jetty.httpConfig.delayDispatchUntilContent" deprecated="jetty.delayDispatchUntilContent" default="true"/></Set>
<Set name="maxErrorDispatches"><Property name="jetty.httpConfig.maxErrorDispatches" default="10"/></Set>
<Set name="blockingTimeout"><Property deprecated="jetty.httpConfig.blockingTimeout" name="jetty.httpConfig.blockingTimeout.DEPRECATED" default="-1"/></Set>
<Set name="persistentConnectionsEnabled"><Property name="jetty.httpConfig.persistentConnectionsEnabled" default="true"/></Set>
<Set name="cookieCompliance"><Call class="org.eclipse.jetty.http.CookieCompliance" name="valueOf"><Arg><Property name="jetty.httpConfig.cookieCompliance" default="RFC6265"/></Arg></Call></Set>
<Set name="multiPartFormDataCompliance"><Call class="org.eclipse.jetty.server.MultiPartFormDataCompliance" name="valueOf"><Arg><Property name="jetty.httpConfig.multiPartFormDataCompliance" default="RFC7578"/></Arg></Call></Set>
</New>
<!-- =========================================================== -->
<!-- Set the default handler structure for the Server -->
<!-- A handler collection is used to pass received requests to -->
<!-- both the ContextHandlerCollection, which selects the next -->
<!-- handler by context path and virtual host, and the -->
<!-- DefaultHandler, which handles any requests not handled by -->
<!-- the context handlers. -->
<!-- Other handlers may be added to the "Handlers" collection, -->
<!-- for example the jetty-requestlog.xml file adds the -->
<!-- RequestLogHandler after the default handler -->
<!-- =========================================================== -->
<Set name="handler">
<New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
<Set name="handlers">
<Array type="org.eclipse.jetty.server.Handler">
<Item>
<New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
</Item>
<Item>
<New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
</Item>
</Array>
</Set>
</New>
</Set>
<!-- =========================================================== -->
<!-- extra server options -->
<!-- =========================================================== -->
<Set name="stopAtShutdown"><Property name="jetty.server.stopAtShutdown" default="true"/></Set>
<Set name="stopTimeout"><Property name="jetty.server.stopTimeout" default="5000"/></Set>
<Set name="dumpAfterStart"><Property name="jetty.server.dumpAfterStart" deprecated="jetty.dump.start" default="false"/></Set>
<Set name="dumpBeforeStop"><Property name="jetty.server.dumpBeforeStop" deprecated="jetty.dump.stop" default="false"/></Set>
</Configure>
在此文件中,我添加了以下内容
<Ref refid="DeploymentManager">
<Call name="addLifeCycleBinding">
<Arg>
<New
class="org.eclipse.jetty.cdi.servlet.WeldDeploymentBinding">
</New>
</Arg>
</Call>
并且我将此依赖项添加到了maven
<dependency>
<groupId>org.eclipse.jetty.cdi</groupId>
<artifactId>cdi-servlet</artifactId>
<version>9.4.12.v20180830</version>
</dependency>
但是我遇到了这个错误
MBP-de-Admin:jetty-distribution-9.4.12.v20180830 admin$ java -jar start.jar
2019-02-06 07:49:05.745:INFO::main: Logging initialized @841ms to org.eclipse.jetty.util.log.StdErrLog
2019-02-06 07:49:05.912:WARN:oejx.XmlConfiguration:main: Config error at <Ref refid="DeploymentManager"><Call name="addLifeCycleBinding"><Arg>| <New class="org.eclipse.jetty.cdi.servlet.WeldDeploymentBinding"/>| </Arg></Call></Ref> java.lang.IllegalStateException: No object for refid=DeploymentManager in file:/Users/admin/Application-Marwen/Jetty/jetty-distribution-9.4.12.v20180830/etc/jetty.xml
2019-02-06 07:49:05.913:WARN:oejx.XmlConfiguration:main:
java.lang.IllegalStateException: No object for refid=DeploymentManager
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.refObj(XmlConfiguration.java:891)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:487)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:413)
at org.eclipse.jetty.xml.XmlConfiguration.configure(XmlConfiguration.java:311)
at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1558)
at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1512)