简体   繁体   English

使用Jersey冲突的Tomcat上下文

[英]Tomcat Context using Jersey conflict

I am using jersey to create a web server 我正在使用jersey创建Web服务器

my project directory has the following mapping 我的项目目录具有以下映射

ProjectName 
     |.. src/main/java
       |.. folder1
         |.. restEndpoint1.java , restendpoint2.java etc 

an example of how restEndpoint1.java looks is restEndpoint1.java外观的一个示例是

@Path("/static1/static2")
public class DoStuff {

@POST
@Path("/static3")
@Consumes(MediaType.APPLICATION_XML)
@Produces("application/xml")
public Response validation(String inputXML){

so an example of my url when deployed to tomcat is 所以当我的网址部署到tomcat的示例是

 localhost:port/projectName/foldername/{restendpoint1.path}

my web.xml is 我的web.xml是

<servlet>
        <servlet-name>jersey-servlet</servlet-name>
        <servlet-class>
            com.sun.jersey.spi.container.servlet.ServletContainer
        </servlet-class>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>folder1</param-value>
        </init-param>
        <init-param>
            <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
            <param-value>true</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>jersey-servlet</servlet-name>
        <url-pattern>/folder1/*</url-pattern>
    </servlet-mapping>

Now I have to deploy this war as different contexts using the Context path in the tomcat web UI ( I am using Tomcat 7) 现在,我必须使用tomcat Web UI中的Context路径将这场战争部署为不同的上下文(我正在使用Tomcat 7)

ie I would like the url's to be 即我希望URL是

http://localhost:port/{context1}/{restendpoint1.path}

http://localhost:port/{context2}/{restendpoint1.path}

I know that each context will have all the rest endpoints exposed to them but I dnt care about that , I just need to map it this way . 我知道每个上下文都会有所有其他终结点,但是我对此并不关心,我只需要以这种方式进行映射。 The problem I am facing is 我面临的问题是

1) in the web.xml I need to give a folder name as the param so that becomes a root , but with this context requirement I cannot do it . 1)在web.xml中,我需要提供一个文件夹名称作为参数,以使其成为根,但是根据这种上下文要求,我不能这样做。 Also I cannot map to each java class independently ( can I??) 我也不能独立地映射到每个java类(可以吗?)

2) In the tomcat UI how do I deploy my app using different contexts , I can only upload war or give the context and using a URL of the war on a server 2)在tomcat UI中,如何使用不同的上下文部署应用程序,我只能上载war或提供上下文,并在服务器上使用war的URL

Solved by changing the mapping in the web.xml 通过更改web.xml中的映射来解决

 <servlet-mapping>
        <servlet-name>jersey-servlet</servlet-name>
        <url-pattern>/folder1/*</url-pattern>
    </servlet-mapping>

to

<servlet-mapping>
        <servlet-name>jersey-servlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM