使用 Tomcat 实现 Rest Easy
我有一个动态 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
显然,您需要将 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.
我刚刚使用 Maven 和 NetBeans 遇到了同样的问题。答案是将 jboss maven 存储库添加到您的 pom.xml 文件中。仅添加
....
(例如通过使用netbeans maven浏览器)不会安装resteasy的依赖项。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.我有同样的异常,并像这样修复它:
是否有可能您将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).