有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Jersey 1.19,TOME+1.74。网状物xml URL模式工作不正常

使用:泽西1.19,托米加1.74 我可以通过两个不同的URL访问相同的控制器方法

http://localhost:8080/hello
http://localhost:8080/rest/hello

网络。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!";
    }
}

对TOME系统进行了添加。基于在stackoverfow上找到的结果的属性

 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模式限制访问


共 (1) 个答案

  1. # 1 楼答案

    您没有提到您正在使用哪种风格的tomee,但是如果发行版提供JAXR(-jaxrs或-plus),则需要在conf/conf.d/cxf-rs.properties中添加disabled=true