问题描述:

I need to disable default rest easy search in JBoss EAP 6.3.

I need to deploy the same EAR in JBoss as well as weblogic and websphere, hence cannot make changes in web.xml that is specific to JBoss.

Java Class:

package com.first;

import javax.ws.rs.GET;

import javax.ws.rs.Path;

import javax.ws.rs.Produces;

import javax.ws.rs.core.MediaType;

@Path("/hello")

public class Hello {

@GET

@Produces(MediaType.TEXT_PLAIN)

public String sayPlainTextHello() {

return "Hello sayPlainTextHello";

}

@GET

@Produces(MediaType.TEXT_XML)

public String sayXMLHello() {

return "<?xml version=\"1.0\"?>" + "<hello> Hello sayXMLHello" + "</hello>";

}

@GET

@Produces(MediaType.TEXT_HTML)

public String sayHtmlHello() {

return "<html> " + "<title>" + "Hello sayHtmlHello" + "</title>"

+ "<body><h1>" + "Hello String" + "</body></h1>" + "</html> ";

}

}

Web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">

<display-name>com.first</display-name>

<servlet>

<servlet-name>Jersey REST Service</servlet-name>

<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>

<init-param>

<param-name>com.sun.jersey.config.property.packages</param-name>

<param-value>com.first</param-value>

</init-param>

<load-on-startup>1</load-on-startup>

</servlet>

<servlet-mapping>

<servlet-name>Jersey REST Service</servlet-name>

<url-pattern>/rest/*</url-pattern>

</servlet-mapping>

<context-param>

<param-name>resteasy.scan</param-name>

<param-value>false</param-value>

</context-param>

<context-param>

<param-name>resteasy.scan.providers</param-name>

<param-value>false</param-value>

</context-param>

<context-param>

<param-name>resteasy.scan.resources</param-name>

<param-value>false</param-value>

</context-param>

</web-app>

jboss-deployment-structure.xml

<?xml version="1.0" encoding="UTF-8"?>

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">

<deployment>

<exclude-subsystems>

<!-- Disable the default JAX-RS subsystem -->

<subsystem name="jaxrs" />

</exclude-subsystems>

</deployment>

</jboss-deployment-structure>

This throws an error: The ResourceConfig instance does not contain any root resource classes.

If I remove below lines from web.xml, it works fine:

<init-param>

<param-name>com.sun.jersey.config.property.packages</param-name>

<param-value>com.first</param-value>

</init-param>

Can anyone please suggest me what should be the ideal approach without making changes in web.xml(ideally it should work in all servers)

Thanks

网友答案:

I haven't tested this myself, but have you tried just excluding the resteasy modules, and not the entire jaxrs subsystem? The jaxrs module is likely required to be on the classpath to support your jersey implementation.

Specifically:

  • resteasy-atom-provider
  • resteasy-cdi
  • resteasy-hibernatevalidator-provider
  • resteasy-jackson-provider
  • resteasy-jaxb-provider
  • resteasy-jaxrs
  • resteasy-jettison-provider
  • resteasy-jsapi
  • resteasy-multipart-provider
  • resteasy-spring
  • resteasy-yaml-provider
相关阅读:
Top