2

我们可以在 Java EE 中为一个项目添加多个上下文根吗?

我试过这个但不适合我:

<wls:context-root>/ayz</wls:context-root>
<wls:context-root>/abc</wls:context-root>
4

5 回答 5

3

一个 Web 应用程序只能有一个“上下文根”。如何定义它取决于您使用的容器。例如,在 WebSphere 中,您可以在 application.xml 中定义它。

<module id="Module_1332249637478">
  <web>
    <web-uri>XxxWeb.war</web-uri>
    <context-root>/xxx</context-root>
  </web>
</module>
于 2013-04-30T11:19:00.363 回答
0

在 weblogis 中执行此操作的一种方法是..将应用程序部署为共享库.. 使用空 web.xml 和 weblogic.xml 创建另一个应用程序(让我们调用虚拟) <library-ref> and <context-root>(使用您要访问应用程序的),它指的是共享图书馆。如果您希望它引用多个上下文根,请创建尽可能多的虚拟应用程序。

于 2014-03-05T07:06:09.177 回答
0

如果您使用的是 tomcat 转到 tomcat 的 conf\Catalina\localhost 文件夹。添加 test1-server.xml 和 test2-server.xml。在 test1-server.xml 和 test2-server.xml 文件中添加以下内容

<Context path="/test-server" docBase="D:\\pathtofilessystemwhere test-server islocated \test-server" />

当您运行 tomcat 时,test1-server.xml 和 test2-server.xml 的上下文路径可能不同,它将从两个上下文路径加载

于 2013-04-30T12:15:45.800 回答
0

当然可以,

如何,取决于应用程序。服务器/网络容器。例如在tomcat中,如果你打开/conf/server.xml你会看到如何定义一个上下文,例如

<Context path="/hello" docBase="../../../../work/hello" >

path - /hello - is the web path
docBase - "../../../../work/hello - is the file system location

只要符合 web-directory 标准,大多数 web 容器将允许您通过在 ROOT 目录下添加 web-directory 来定义上下文。

但在大多数情况下,您可能希望将目录放在不同的位置并使用 Context 标签。

于 2013-04-30T11:09:28.110 回答
0

据我所知,在 jboss 方面,每个应用程序只能有 1 个。它可以通过使用 ejb3 注释的无状态 bean 以多种方式(在本例中)定义:

@Stateless
@WebService(
    name = "MyService",
    targetNamespace = "http://myurl.co.uk/MyContext/MyService",
    serviceName = "MyService")
@WebContext(contextRoot = "/MyContext" , urlPattern = "/MyService")
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
@HandlerChain(file = "META-INF/jaxws-handlers-server.xml")
public class MyIface {

    // Inject the persistence layer
    @EJB(beanInterface=IPersistenceLayerBean.class)
    private IPersistenceLayerBean persistenceLayer;

    @WebMethod
    public Response doSomething() {
        return persistenceLayer.helloWorld();
    }

}

您可以在应用程序中定义多个接口,每个接口都有自己的“urlPattern”,但它们必须共享相同的“contextRoot”,否则您会看到一个错误。

于 2013-04-30T13:25:35.750 回答