我搜索了很多关于这个问题的主题,有些人告诉我使用resteasy-servlet-intialler,有些人使用RestEasyBootstrap,但它无法正常工作而只是回复404页面。它让我疯狂。你可以帮助我出?
<servlet>
<servlet-name>Resteasy</servlet-name>
<servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.restfully.shop.services.ShoppingApplication</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Resteasy</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
这就是简单的应用程序:
@ApplicationPath("/services")
public class ShoppingApplication extends Application {
private Set<Object> singletons =new HashSet<Object>();
private Set<Class<?>> empty=new HashSet<Class<?>>();
public ShoppingApplication()
{
singletons.add(new CustomerResource());
}
@Override
public Set<Class<?>> getClasses() {
return empty;
}
@Override
public Set<Object> getSingletons() {
return singletons;
}
}
这里是gradle:
dependencies {
compile group:'org.jboss.resteasy',name:'resteasy-jaxrs',version:'3.1.2.Final'
compile group:'org.jboss.resteasy',name:'resteasy-jackson-provider',version:'3.1.2.Final'
compile group:'org.jboss.resteasy',name:'resteasy-guice',version:'3.1.2.Final'
compile group: 'org.jboss.resteasy',name:'resteasy-servlet-initializer',version:'3.1.2.Final'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
答案 0 :(得分:0)
删除@ApplicationPath
注释,因为由于您的web.xml配置,它是多余的。
将web.xml更改为:
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/services</param-value>
</context-param>
<servlet>
<servlet-name>Resteasy</servlet-name>
<servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.restfully.shop.services.ShoppingApplication</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Resteasy</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
注意更新的url-pattern。