1

当我PortalUtil.getPortalPort(secure)在调度程序中使用它时,它总是返回 -1 而不是正确的端口号 8080。

boolean secure = "https".equalsIgnoreCase( PropsUtil.get( PropsKeys.WEB_SERVER_PROTOCOL ) );
Company company = CompanyLocalServiceUtil.getCompanies().get(0);
String portalURL = PortalUtil.getPortalURL(company.getVirtualHostname(), PortalUtil.getPortalPort(secure), secure);

如果我从托管 bean 运行代码,它工作正常。

有没有其他方法可以从调度程序获取服务器端口?

4

1 回答 1

1

Since you are executing the code from scheduler, and you don't have reference to request object, you cant get the server port using PortalUtil.

You can try the hack mentioned here. Java EE getting servlet container port

于 2013-09-10T07:50:26.357 回答