使用 Tomcat 实现 Rest Easy

发布于 2024-11-27 18:35:33 字数 2129 浏览 1 评论 0原文

我有一个动态 Web 项目,其中包含一组 jsp 和一个自定义控制器 servlet,效果很好。但是,我还需要在其上实现一个轻松的公开服务,这就是我更改网络的原因。 xml 也包含rest easy servlet。以及调用其余简单资源的应用程序类。但是,当我向 web.xml 添加更改时,它遇到了 Rest easy servlet,但抛出异常..

java.lang.ClassNotFoundException: org.scannotation.AnnotationDB$CrossReferenceException

Web.xml :

   <servlet>
<display-name>ControllerServlet</display-name>
<servlet-name>ControllerServlet</servlet-name>
<servlet-class>com.example.ControllerServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet>
<servlet-name>CollRestApi</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.exampl.RestApiApplication</param-value>
    </init-param>
 </servlet>
<servlet-mapping>
    <servlet-name>ControllerServlet</servlet-name>
    <url-pattern>/ControllerServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>CollRestApi</servlet-name>
    <url-pattern>/or/*</url-pattern>
</servlet-mapping>

Rest Api 应用程序:

public class RestApiApplication extends Application{

private Set<Object> singletons = new HashSet();
private Set<Class<?>> empty = new HashSet();

public RestApiApplication() {
    // ADD YOUR RESTFUL RESOURCES HERE
    this.singletons.add(new CollRestApi());
}

public Set<Class<?>> getClasses()
{
    return this.empty;
}

public Set<Object> getSingletons()
{
    return this.singletons;
}}

并且 CollRestApi .. 正在公开服务..

   @Path("api")@Consumes({ "application/xml", "application/json" })@Produces({application/xml", "application/json" })public class CollRestApi {

/**
 * @return
 */
@GET
@Path("ab")
public Response do() {
    System.out.println("Inside the do Method.");

}}

I have a Dynamic Web Project with a set of jsp's and a custom controller servlet, that is working great. But, I also need to implement a rest easy exposed service on it, and that's why i changed the web. xml to contain rest easy servlet also. and the application class which invokes the rest easy resource. But, when i am adding changes to web.xml, it is hitting rest easy servlet, but throwing exception..

java.lang.ClassNotFoundException: org.scannotation.AnnotationDB$CrossReferenceException

Web.xml :

   <servlet>
<display-name>ControllerServlet</display-name>
<servlet-name>ControllerServlet</servlet-name>
<servlet-class>com.example.ControllerServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet>
<servlet-name>CollRestApi</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.exampl.RestApiApplication</param-value>
    </init-param>
 </servlet>
<servlet-mapping>
    <servlet-name>ControllerServlet</servlet-name>
    <url-pattern>/ControllerServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>CollRestApi</servlet-name>
    <url-pattern>/or/*</url-pattern>
</servlet-mapping>

Rest Api Application :

public class RestApiApplication extends Application{

private Set<Object> singletons = new HashSet();
private Set<Class<?>> empty = new HashSet();

public RestApiApplication() {
    // ADD YOUR RESTFUL RESOURCES HERE
    this.singletons.add(new CollRestApi());
}

public Set<Class<?>> getClasses()
{
    return this.empty;
}

public Set<Object> getSingletons()
{
    return this.singletons;
}}

And CollRestApi.. is having exposed services..

   @Path("api")@Consumes({ "application/xml", "application/json" })@Produces({application/xml", "application/json" })public class CollRestApi {

/**
 * @return
 */
@GET
@Path("ab")
public Response do() {
    System.out.println("Inside the do Method.");

}}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冷清清 2024-12-04 18:35:33

显然,您需要将 scannotation.jar 添加到类路径中。 RESTEasy 2.2.2.GA 依赖于您也需要的 scannotation-1.0.3 和 javassist-3.12.1.GA.jar。

Obviously, you need to add scannotation.jar to your classpath. RESTEasy 2.2.2.GA depends on scannotation-1.0.3 and javassist-3.12.1.GA.jar which you also need.

风尘浪孓 2024-12-04 18:35:33

我刚刚使用 Maven 和 NetBeans 遇到了同样的问题。答案是将 jboss maven 存储库添加到您的 pom.xml 文件中。仅添加....(例如通过使用netbeans maven浏览器)不会安装resteasy的依赖项。

<repositories>
        <repository>
            <id>jboss</id>
            <url>http://repository.jboss.org/nexus/content/groups/public-jboss/</url>
        </repository>
</repositories>

I just faced the same problem using maven and netbeans. The answer is to add the jboss maven repository to your pom.xml-file. Just adding <dependency>....</dependency>, e.g. by using netbeans maven browser, doesn't install the dependecies of resteasy.

<repositories>
        <repository>
            <id>jboss</id>
            <url>http://repository.jboss.org/nexus/content/groups/public-jboss/</url>
        </repository>
</repositories>
看春风乍起 2024-12-04 18:35:33

我有同样的异常,并像这样修复它:

是否有可能您将resteasy**.jar库放在与其他resteasy支持库(例如scannotation-1.0.3.jar)不同的位置(例如tomcat lib目录)(例如在你的战争文件 WEB-INF/lib 中)?

在这样的配置中,您的 Resteasy 类将在不同的类加载器中启动,该类加载器看不到 scannotation-1.0.3.jar 类。

=>尝试将所有 Resteasy jar 文件放在任一位置(最好是 .war 文件)。

I had the same exception, and fixed it like this:

Is it possible you have the resteasy**.jar libraries in a different location (e.g. the tomcat lib dir) than other resteasy-supporting libs like scannotation-1.0.3.jar (e.g. in your war file WEB-INF/lib) ?

In such a configuration your resteasy classes will start in a different classloader which does not see the scannotation-1.0.3.jar classes.

=> Try putting all resteasy jar files in either one of the locations (preferably your .war file).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文