Java tomcat上的多租户

Java tomcat上的多租户,java,json,tomcat,Java,Json,Tomcat,我已经在Tomcat上公开并实现了一组JSON API。 我希望通过以下URL方法在Tomcat上实现这些API的多租户: companyname1.domain.com/api/getUsers... companyname2.domain.com/api/getUsers... companyname3.domain.com/api/getUsers... 让我知道是否有使用上下文或其他机制实现它的最佳实践。我不想为每个公司创建一个单独的Tomcat实例。 此外,公司注册后,是否有任何方法

我已经在Tomcat上公开并实现了一组JSON API。 我希望通过以下URL方法在Tomcat上实现这些API的多租户:

companyname1.domain.com/api/getUsers...
companyname2.domain.com/api/getUsers...
companyname3.domain.com/api/getUsers...
让我知道是否有使用上下文或其他机制实现它的最佳实践。我不想为每个公司创建一个单独的Tomcat实例。 此外,公司注册后,是否有任何方法可以动态创建它

提前谢谢大家,,
Moshe

这可以通过使用多个反向代理来完成,这些反向代理为Tomcat webapp提供不同的参数。最简单的设置(使用ApacheHTTP和)可能是保留原始请求的主机,并在web应用程序中解决该问题

<VirtualHost *:80>
    ServerName companyname1.domain.com

    ProxyPass / ajp://localhost:8009/
    ProxyPassReverse / ajp://localhost:8009/
    ProxyPreserveHost On
</VirtualHost>

<VirtualHost *:80>
    ServerName companyname2.domain.com

    ProxyPass /api ajp://localhost:8009/
    ProxyPassReverse / ajp://localhost:8009/
    ProxyPreserveHost On
</VirtualHost>

<VirtualHost *:80>
    ServerName companyname3.domain.com

    ProxyPass / ajp://localhost:8009/
    ProxyPassReverse / ajp://localhost:8009/
    ProxyPreserveHost On
</VirtualHost>

ServerName companyname1.domain.com
ProxyPass/ajp://localhost:8009/
ProxyPassReverse/ajp://localhost:8009/
代理主机
ServerName companyname2.domain.com
ProxyPass/apiajp://localhost:8009/
ProxyPassReverse/ajp://localhost:8009/
代理主机
ServerName companyname3.domain.com
ProxyPass/ajp://localhost:8009/
ProxyPassReverse/ajp://localhost:8009/
代理主机
所以URL中需要应用程序名

companyname1.domain.com/abc/api/getUsers
companyname2.domain.com/xyz/api/getUsers
companyname3.domain.com/fgf/api/getUsers
在Tomcatsserver.xml中创建几个侦听域的文件。这些目录应指向不同的webapps目录,将特定应用程序托管在根目录中:

<Host name="localhost" appBase="domain1-webapps" autoDeploy="true" unpackWARs="true"></Host>
<Host name="companyname1.domain.com" appBase="domain1-webapps" autoDeploy="true" unpackWARs="true"></Host>
<Host name="companyname2.domain.com" appBase="domain2-webapps" autoDeploy="true" unpackWARs="true"></Host>
...

...
获取详细信息。通过这个链接。

谢谢。这对我帮助很大
<Host name="localhost" appBase="domain1-webapps" autoDeploy="true" unpackWARs="true"></Host>
<Host name="companyname1.domain.com" appBase="domain1-webapps" autoDeploy="true" unpackWARs="true"></Host>
<Host name="companyname2.domain.com" appBase="domain2-webapps" autoDeploy="true" unpackWARs="true"></Host>
...
We can use server context setting. like as per tomcat server specification. 
The Host element represents a virtual host, which is an association of a network name for a server (such as "www.mycompany.com") with the particular server on which Tomcat is running. For clients to be able to connect to a Tomcat server using its network name, this name must be registered in the Domain Name Service (DNS) server that manages the Internet domain you belong to - contact your Network Administrator for more information.

In many cases, System Administrators wish to associate more than one network name (such as www.mycompany.com and company.com) with the same virtual host and applications. This can be accomplished using the Host Name Aliases feature discussed below.

One or more Host elements are nested inside an Engine element. Inside the Host element, you can nest Context elements for the web applications associated with this virtual host. Exactly one of the Hosts associated with each Engine MUST have a name matching the defaultHost attribute of that Engine.

Clients normally use host names to identify the server they wish to connect to. This host name is also included in the HTTP request headers. Tomcat extracts the host name from the HTTP headers and looks for a Host with a matching name. If no match is found, the request is routed to the default host. The name of the default host does not have to match a DNS name (although it can) since any request where the DNS name does not match the name of a Host element will be routed to the default host.