[英]Jersey 1.19, TomEE+ 1.74. Web.xml Url-Pattern is not working correctly
使用:Jersey 1.19,TomEE Plus 1.74,我可以通过两个不同的URL访问相同的控制器方法。
http://localhost:8080/hello
http://localhost:8080/rest/hello
web.xml中:
<init-param>
<param-name>
com.sun.jersey.config.property.packages
</param-name>
<paramvalue>
mif.ubermensch.labanorogiraite.presentation.controllers
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>LabanoroGiraite</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
控制器:
@Path("/hello")
public class HelloController {
@GET
@Produces("text/plain")
public String Hello(){
return "Hello, Restful world!";
}
}
根据在stackoverfow上找到的结果对TomEE system.properties进行了添加
openejb.api.javax.ws.rs.Path.validation=false
com.sun.jersey.server.impl.cdi.lookupExtensionInBeanManager=true
如果没有这两个,访问带有/ rest /前缀的URL将引起异常:
javax.naming.NameNotFoundException: Name [com] is not bound in this Context. Unable to find [com].
如何仅通过/ api / * url-pattern限制访问?
您没有提到要使用哪种tomee风格,但是如果发行版提供jaxrs(-jaxrs或-plus),则需要在conf / conf.d / cxf-rs.properties中添加disabled = true。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.