1

我尝试在 Java SE 环境中的 Netty 上设置 CDI/Weld 和 JAX-RS/RESTEasy,但我得到的只是以下异常:

javax.ws.rs.NotFoundException: Could not find resource for full path: http://localhost:8000/

我的项目具有以下依赖项:

<dependency>
  <groupId>org.jboss.resteasy</groupId>
  <artifactId>resteasy-netty4</artifactId>
  <version>3.0.5.Final</version>
</dependency>
<dependency>
  <groupId>org.jboss.resteasy</groupId>
  <artifactId>resteasy-cdi</artifactId>
  <version>3.0.5.Final</version>
</dependency>
<dependency>
  <groupId>io.netty</groupId>
  <artifactId>netty-all</artifactId>
  <version>4.0.12.Final</version>
</dependency>

我在 src/main/resources/META-INF 目录中放置了一个 beans.xml 文件来启用 CDI。

启动netty的代码:

@Singleton
public class App {

  private static NettyJaxrsServer netty;

  public void printHello(
          @Observes ContainerInitialized event,
          @Parameters List<String> parameters) 
          throws Exception {
    System.out.println("Starting Netty ...");
    ResteasyDeployment deployment = new ResteasyDeployment();
    netty = new NettyJaxrsServer();
    netty.setDeployment(deployment);
    netty.setPort(8000);
    netty.setRootResourcePath("");
    netty.setSecurityDomain(null);
    netty.start();
  }

示例资源如下所示:

@Path("/hi") // tried "/" too
public class Index {

  @GET
  public String get() {
    return "Hi!";
  }
}

由于所有这些都不起作用,我添加了一个应用程序类:

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ApplicationPath("/")
public class DemoApplication  extends Application {
  // empty
}

但是错误信息仍然是一样的。

什么不见​​了?如何设置 Weld 和 RESTEasy?

4

1 回答 1

1

你检查过这个链接吗? Tomcat 7,焊接,RESTEasy 不扫描 JAR

它说你应该beans.xml输入 WEB-INF 而不是 META-INF。

于 2014-01-20T21:58:06.690 回答