Enabling automatic scanning using resteasy 3.0.10 with wildfly 8.2

I am trying to find out what is my problem when setting up a new Wildfly 8.2 server with a simple restEasy 3.0.10 application.

my web application is simplified.

src/main/ java/my-package/ RootApplication.java HomePageResource.java webapp/ index.html WEB-INF/ beans.xml web.xml 

web.xml and beans.xml look like this

 ---- web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" metadata-complete="false"> </web-app> ---- beans.xml <beans 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/beans_1_0.xsd"> </beans> 

in RootApplication.java I have

 @ApplicationPath("/app") public class RootApplication extends Application { private Set<Object> singletons = new HashSet<>(); public RootApplication() { singletons.add(new HomePageResource()); } @Override public Set<Object> getSingletons() { return singletons; } } // ResourceProvider is a simple class hiding getResource and createStreamer @Path("/") public class HomePageResource extends ResourceProvider { private final static Logger logger = LoggerFactory.getLogger(HomePageResource.class); @GET @Produces(MediaType.TEXT_HTML) public Response getHomePage() { final InputStream homePageResource = getResource("/static/view/home/home.html"); return Response.ok(createStreamer(homePageResource)).build(); } } 

but I never specified resource classes inside the application, and RestEasy could always scan WAR content. And if I remove everything from RootApplication, like this.

 @ApplicationPath("/app") public class RootApplication extends Application { } 

In any case, the documentation also says ( https://docs.jboss.org/resteasy/docs/3.0.9.Final/userguide/html_single/ )

Since we do not use jax-rs servlet mapping, we must define an application class annotated with the @ApplicationPath annotation. If you return an empty set for classes and singles, your WAR will be scanned for JAX-RS resources and provider resources.

any hints what can i do wrong with this simple installation ??? and one more question: I can remove beans.xml to use guice DI, I understand that this problem has nothing to do with CDI / WELD.

my pom.xml looks like

 <dependencyManagement> <dependencies> <dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-bom</artifactId> <version>3.0.10</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> </dependency> <dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>jaxrs-api</artifactId> </dependency> <dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-jackson-provider</artifactId> </dependency> <dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-multipart-provider</artifactId> </dependency> </dependencies> 
+5
source share
1 answer

There is a good tutorial from mkyong that gives examples of how to configure a web service application with or without resteasy.scan .

Based on your question, is your web.xml empty? This would mean that resteasy.scan set to false according to the documentation :

resteasy.scan - Default value: false - automatically scan WEB-INF / lib jars and the WEB-INF / classes directory for @Provider and JAX-RS resource classes (@Path, @GET, @POST, etc.). and register them

I usually set resteasy.scan to false and register my resources manually, because sometimes WEB-INF/lib contained providers / resources and they interrupted my application. Here is the configuration I'm using:

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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 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>My application name</display-name> <context-param> <param-name>resteasy.scan</param-name> <param-value>false</param-value> </context-param> <servlet> <servlet-name>resteasy-servlet</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>com.foo.bar.Configuration</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>resteasy-servlet</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> </web-app> 

Configuration.java

 package com.foo.bar; import java.util.HashSet; import java.util.Set; import javax.ws.rs.core.Application; public class Configuration extends Application { public Configuration() { } @Override public Set<Class<?>> getClasses() { Set<Class<?>> classes = new HashSet<Class<?>>(); classes.add(EntryPoint.class); return classes; } } 
+3
source

Source: https://habr.com/ru/post/1209276/


All Articles