Java-g
Java-g

Reputation: 143

RestEasy Boss unable to scan Web-Inf for Jax-RS annotations

i get the error: Unable to scan WEB-INF for JAX-RS annotations, you must manually register your classes/resources

I have the following maven config:

<dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-servlet-initializer</artifactId>
            <version>3.0.4.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-cdi</artifactId>
            <version>3.0.4.Final</version>
            <exclusions>
                <exclusion>
                    <groupId>org.jboss.resteasy</groupId>
                    <artifactId>resteasy-jaxrs</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
 <dependency>
            <groupId>org.jboss.weld.servlet</groupId>
            <artifactId>weld-servlet</artifactId>
            <version>2.2.14.Final</version>
        </dependency>

My java class is a minimalistic call.

@Path("test")
public class MyResource {

//    @Inject
//    private JpaUserDao userDao;

    /**
     * Method handling HTTP GET requests. The returned object will be sent
     * to the client as "text/plain" media type.
     *
     * @return String that will be returned as a text/plain response.
     */
    @GET
    @Produces(MediaType.TEXT_XML)
    public String getIt() {
        System.out.printf("");
        return "Got it!";
    }



}

I want to marry rest easy with cdi. In my web app i enabled the scan config, because i want that the annotation @path is found automatically.

My web.xml

<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>
<context-param>
    <param-name>resteasy.scan</param-name>
    <param-value>true</param-value>
</context-param>

Upvotes: 0

Views: 1038

Answers (1)

chathura rupasinghe
chathura rupasinghe

Reputation: 246

You are using restEasy 3.0.+ so use a design pattern like singleton to initiate your webservice.

@ApplicationPath("/mainPathToWebService")
public class singletonHelper extends Application {

    @SuppressWarnings("unchecked")
    public Set<Class<?>> getClasses() {
        return new HashSet<Class<?>>(Arrays.asList(MyResource.class));
    }

}

Upvotes: 0

Related Questions