【问题标题】:RestEasy Boss unable to scan Web-Inf for Jax-RS annotationsRestEasy Boss 无法扫描 Web-Inf 以获取 Jax-RS 注释
【发布时间】:2016-05-25 13:06:51
【问题描述】:

我收到错误:无法扫描 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>

【问题讨论】:

  • Tomcat 你要部署什么?
  • 如果没有其他信息,您的问题将无法回答,例如:您使用的服务器(和版本)、您得到的确切错误/堆栈跟踪。顺便说一句:在这里你可以找到some workaround

标签: jboss cdi resteasy


【解决方案1】:

您使用的是 restEasy 3.0.+,因此请使用像单例这样的设计模式来启动您的 Web 服务。

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

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

}

【讨论】:

    猜你喜欢
    • 2011-08-18
    • 2016-10-02
    • 2014-05-18
    • 1970-01-01
    • 1970-01-01
    • 2014-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多