我正在嘗試使用JX-RS創建Java EE應用程序。我有它使用以下配置工作:使用web.xml配置Glassfish 4的JX-RS導致錯誤
@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.
我怎麼能防止這個錯誤?