RestEasy Boss无法扫描Web-Inf以获取Jax-RS注释

时间:2016-02-14 18:34:26

标签: jboss cdi resteasy

我收到错误:无法扫描WEB-INF以获取JAX-RS注释,您必须手动注册您的类/资源

我有以下maven配置:

<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>

我的java类是一个简约的调用。

@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!";
    }



}

我想和cdi一起轻松休息。在我的网络应用程序中,我启用了扫描配置,因为我希望自动找到注释@path。

我的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>

1 个答案:

答案 0 :(得分:0)

您正在使用restEasy 3.0。+因此请使用像singleton这样的设计模式来启动您的Web服务。

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

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

}