如何在WebLogic 11g上两次部署相同的Web应用程序?

时间:2022-09-06 20:09:55

We have developed a JEE5 web application (WAR) and running it in production under WebLogic 11g (10.3.5).

我们开发了一个JEE5 Web应用程序(WAR),并在WebLogic 11g(10.3.5)下运行它。

Now the same application should be deployed as separate applications for different customers (different URLs, different data) on the same WebLogic.

现在,应将同一应用程序部署为同一WebLogic上不同客户(不同URL,不同数据)的单独应用程序。

I managed the first part by setting different context roots after deployment for each of them.

我通过在部署之后为每个部分设置不同的上下文根来管理第一部分。

But I have yet to make them use different datasources - and since I want to avoid customer specific builds, the persistence.xml is the same for all applications, thus also the persistence unit name.

但我还没有让他们使用不同的数据源 - 因为我想避免客户特定的构建,所以persistence.xml对于所有应用程序都是相同的,因此也是持久性单元名称。

What is the best setup for this scenario? Am I forced making separate builds and by that different WARs or do I have to separate Managed Servers or Domains wihtin the server or is there a better way to solve it?

这种情况的最佳设置是什么?我是否强制进行单独的构建以及不同的WAR,或者我必须将服务器或域与服务器分开,还是有更好的方法来解决它?

3 个解决方案

#1


0  

ServletContextListener.contextInitialized can look at the ServletContext and figure out which deployment is which

ServletContextListener.contextInitialized可以查看ServletContext并找出哪个部署

in web.xml, define a servlet context listener:

在web.xml中,定义一个servlet上下文侦听器:

<listener>
  <listener-class>com.path.YourServletContextListener</listener-class>
</listener>

and then in YourServletContextListener.java, add a contextInitialized method like this:

然后在YourServletContextListener.java中,添加一个contextInitialized方法,如下所示:

public void contextInitialized(ServletContextEvent sce)
{
  ServletContext sc = sce.getServletContext();
  String name = sc.getContextPath();
  ...
}

my thought is that you can use that name to select from multiple data sources that you have configured. depending on how you've been deployed, you'll make a different database connection and have the correct application's data.

我的想法是你可以使用该名称从已配置的多个数据源中进行选择。根据您的部署方式,您将建立不同的数据库连接并拥有正确的应用程序数据。

#2


0  

It seems to me from what I saw in the Oracle documentation, that having several domains is the only way to separate data sources with the same persistence unit name - which is bad, since this basically means running two WLS in parallel.

在我看来,在Oracle文档中看来,拥有多个域是使用相同的持久性单元名称分隔数据源的唯一方法 - 这很糟糕,因为这基本上意味着并行运行两个WLS。

For this reason I decided to go with building individual WAR files (which I tried to avoid initially), to include customer-specific persistence.xml files and specifying customer-specific datasources in the WLS.

出于这个原因,我决定构建单独的WAR文件(我最初试图避免),包括客户特定的persistence.xml文件并在WLS中指定客户特定的数据源。

#3


0  

I know this thread is very old,but replying so that it may help someone with the same question stumbling on this thread.

我知道这个帖子很老了,但回复以便它可以帮助有同样问题的人在这个帖子上磕磕绊绊。

The latest weblogic 12.2.1 comes with Multi-tenancy(add-on I guess) which can let you run same applications in a single domain.

最新的weblogic 12.2.1带有Multi-tenancy(我猜是附加组件),它可以让你在一个域中运行相同的应用程序。

Edit: Weblogic 12.2.1 introduced concept called Partitions. Partitions are both config and run-time subdivision of a weblogic Domain. In a single weblogic domain you can create multiple partitions. Each partition will have one or more resource groups. Resource groups are the logical grouping of weblogic resorces like data sources,jms,Java EE apps ,etc. For example to achieve what the original posts asked for , we create a Resource Group template with the web-application and the datasource as the resources. In the Data source configuration we can provide a place holder variable instead of actual URL as DB URL. Then we can create two partitions that refers to this Resource Group Template(Each partition will now have a separate web application and data source) . Each partition will override the DB URL property there by creating two data sources with same JNDI name.In each Partition we create virtual host/port so that the client can use that to access the application running in the respective partitions.

编辑:Weblogic 12.2.1引入了名为Partitions的概念。分区是weblogic域的配置和运行时细分。在单个weblogic域中,您可以创建多个分区。每个分区都有一个或多个资源组。资源组是weblogic resorces的逻辑分组,如数据源,jms,Java EE应用程序等。例如,为了实现原始帖子所要求的内容,我们创建了一个资源组模板,其中包含Web应用程序和数据源作为资源。在数据源配置中,我们可以提供占位符变量而不是实际URL作为DB URL。然后我们可以创建两个引用此资源组模板的分区(每个分区现在都有一个单独的Web应用程序和数据源)。每个分区将通过创建具有相同JNDI名称的两个数据源来覆盖DB URL属性。在每个分区中,我们创建虚拟主机/端口,以便客户端可以使用它来访问在相应分区中运行的应用程序。

A better and more detailed information on this can be found in https://blogs.oracle.com/WebLogicServer/entry/domain_partitions_for_multi_tenancy

有关详细信息,请访问https://blogs.oracle.com/WebLogicServer/entry/domain_partitions_for_multi_tenancy

#1


0  

ServletContextListener.contextInitialized can look at the ServletContext and figure out which deployment is which

ServletContextListener.contextInitialized可以查看ServletContext并找出哪个部署

in web.xml, define a servlet context listener:

在web.xml中,定义一个servlet上下文侦听器:

<listener>
  <listener-class>com.path.YourServletContextListener</listener-class>
</listener>

and then in YourServletContextListener.java, add a contextInitialized method like this:

然后在YourServletContextListener.java中,添加一个contextInitialized方法,如下所示:

public void contextInitialized(ServletContextEvent sce)
{
  ServletContext sc = sce.getServletContext();
  String name = sc.getContextPath();
  ...
}

my thought is that you can use that name to select from multiple data sources that you have configured. depending on how you've been deployed, you'll make a different database connection and have the correct application's data.

我的想法是你可以使用该名称从已配置的多个数据源中进行选择。根据您的部署方式,您将建立不同的数据库连接并拥有正确的应用程序数据。

#2


0  

It seems to me from what I saw in the Oracle documentation, that having several domains is the only way to separate data sources with the same persistence unit name - which is bad, since this basically means running two WLS in parallel.

在我看来,在Oracle文档中看来,拥有多个域是使用相同的持久性单元名称分隔数据源的唯一方法 - 这很糟糕,因为这基本上意味着并行运行两个WLS。

For this reason I decided to go with building individual WAR files (which I tried to avoid initially), to include customer-specific persistence.xml files and specifying customer-specific datasources in the WLS.

出于这个原因,我决定构建单独的WAR文件(我最初试图避免),包括客户特定的persistence.xml文件并在WLS中指定客户特定的数据源。

#3


0  

I know this thread is very old,but replying so that it may help someone with the same question stumbling on this thread.

我知道这个帖子很老了,但回复以便它可以帮助有同样问题的人在这个帖子上磕磕绊绊。

The latest weblogic 12.2.1 comes with Multi-tenancy(add-on I guess) which can let you run same applications in a single domain.

最新的weblogic 12.2.1带有Multi-tenancy(我猜是附加组件),它可以让你在一个域中运行相同的应用程序。

Edit: Weblogic 12.2.1 introduced concept called Partitions. Partitions are both config and run-time subdivision of a weblogic Domain. In a single weblogic domain you can create multiple partitions. Each partition will have one or more resource groups. Resource groups are the logical grouping of weblogic resorces like data sources,jms,Java EE apps ,etc. For example to achieve what the original posts asked for , we create a Resource Group template with the web-application and the datasource as the resources. In the Data source configuration we can provide a place holder variable instead of actual URL as DB URL. Then we can create two partitions that refers to this Resource Group Template(Each partition will now have a separate web application and data source) . Each partition will override the DB URL property there by creating two data sources with same JNDI name.In each Partition we create virtual host/port so that the client can use that to access the application running in the respective partitions.

编辑:Weblogic 12.2.1引入了名为Partitions的概念。分区是weblogic域的配置和运行时细分。在单个weblogic域中,您可以创建多个分区。每个分区都有一个或多个资源组。资源组是weblogic resorces的逻辑分组,如数据源,jms,Java EE应用程序等。例如,为了实现原始帖子所要求的内容,我们创建了一个资源组模板,其中包含Web应用程序和数据源作为资源。在数据源配置中,我们可以提供占位符变量而不是实际URL作为DB URL。然后我们可以创建两个引用此资源组模板的分区(每个分区现在都有一个单独的Web应用程序和数据源)。每个分区将通过创建具有相同JNDI名称的两个数据源来覆盖DB URL属性。在每个分区中,我们创建虚拟主机/端口,以便客户端可以使用它来访问在相应分区中运行的应用程序。

A better and more detailed information on this can be found in https://blogs.oracle.com/WebLogicServer/entry/domain_partitions_for_multi_tenancy

有关详细信息,请访问https://blogs.oracle.com/WebLogicServer/entry/domain_partitions_for_multi_tenancy