【发布时间】:2014-06-12 17:37:23
【问题描述】:
我正在尝试使用 JX-RS 创建一个 Java EE 应用程序。我已经使用以下配置使其工作:
@ApplicationPath("rs")
public class MyApplication extends Application {
@Override
public Set<Class<?>> getClasses() {
final Set<Class<?>> classes = new HashSet<>();
// register root resource
classes.add(ProbeREST.class);
return classes;
}
}
但是,我更喜欢使用 web.xml 进行配置。我认为与简单的 xml 配置相比,上述内容非常难看,如下所示:
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<servlet-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/rs/*</url-pattern>
</servlet-mapping>
</web-app>
很遗憾,当我尝试部署应用程序时,收到错误消息:
Exception while deploying the app [my_app] : There is no web component by the name of javax.ws.rs.core.Application here.
如何防止出现此错误?
【问题讨论】:
标签: java glassfish jersey web.xml glassfish-4