找不到JavaREST-404资源
我正在尝试访问Hello world(目前)应用程序上的资源。 但是,当我将HTTP状态404部署到Tomcat上并点击URL:localhost:8080/test/rest时,却没有找到它。 以下是我的pom.xml部门:找不到JavaREST-404资源,java,rest,tomcat,glassfish,Java,Rest,Tomcat,Glassfish,我正在尝试访问Hello world(目前)应用程序上的资源。 但是,当我将HTTP状态404部署到Tomcat上并点击URL:localhost:8080/test/rest时,却没有找到它。 以下是我的pom.xml部门: <dependency> <groupId>org.glassfish.jersey.core</groupId> <artifactId>jersey-common</artifact
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>2.26-b03</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.26-b03</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.26-b03</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
你知道我做错了什么吗?试试本地主机:8080/test/test/rest
<servlet-mapping>
<servlet-name >HelloWorld Jersey Service </servlet-name >
<url-pattern >/test/*</url-pattern >
</servlet-mapping>
现在说下一个url路径是test,所以url是localhost:8080/test/test
@Path("/rest")
public String test() {
return "Great success";
}
将/rest作为下一个url,因此其localhost:8080/test/test/rest因为指定了提供程序包,所以您可以尝试使用以下url localhost:8080/com.latin.translator.app/test/rest您需要扩展
javax.ws.rs.core.Application
类
<servlet-mapping>
<servlet-name >HelloWorld Jersey Service </servlet-name >
<url-pattern >/test/*</url-pattern >
</servlet-mapping>
@ApplicationPath("/") // the context root of you application
public class JaxRsConfig extends Application {
private final Set<Class<?>> classes;
public JaxRsConfig() {
HashSet<Class<?>> c = new HashSet<>();
c.add(Test.class); //repeat for all JAX-RS classes in your application
classes = Collections.unmodifiableSet(c);
}
@Override
public Set<Class<?>> getClasses() {
return classes;
}
}
@ApplicationPath(“/”///应用程序的上下文根目录
公共类JaxRsConfig扩展了应用程序{
private final Set>c=new HashSet();
c、 add(Test.class);//对应用程序中的所有JAX-RS类重复此操作
类=集合。不可修改集(c);
}
@凌驾
public set部署的web应用的上下文名称是什么?
@Path("/rest")
public String test() {
return "Great success";
}
@ApplicationPath("/") // the context root of you application
public class JaxRsConfig extends Application {
private final Set<Class<?>> classes;
public JaxRsConfig() {
HashSet<Class<?>> c = new HashSet<>();
c.add(Test.class); //repeat for all JAX-RS classes in your application
classes = Collections.unmodifiableSet(c);
}
@Override
public Set<Class<?>> getClasses() {
return classes;
}
}