为 WebSphere Spring 引导应用程序设置超时

set timeout for a WebSphere Spring boot application

我正在使用 spring 引导应用程序,它 运行 在 LibertyCode 服务器上运行,

我有一个配置了超时的网络服务器:

ClientConfig configuration = new ClientConfig();
        configuration.property(ClientProperties.CONNECT_TIMEOUT, connecTimeout);
        configuration.property(ClientProperties.READ_TIMEOUT, readTimeout);
        apiClient = ClientBuilder.newClient(configuration);
        WebTarget target = apiClient.target(uri);
        Response response = target.request(MediaType.APPLICATION_JSON_VALUE).header("accept", "application/json")
                .header("Content-Type", "application/json").get();

它在我的本地机器上完美运行(基于 tomcat 没有 websphere) 但是当我 运行 WebSphere 服务器上的 war 时,超时被 忽略 ! 这就是我 server.xml 中使用的功能:

   <feature>localConnector-1.0</feature>
        <feature>restConnector-1.0</feature>
        <feature>beanValidation-1.1</feature>
        <feature>adminCenter-1.0</feature>
        <feature>transportSecurity-1.0</feature>

请帮忙

你能试试把 <feature>restConnector-1.0</feature> 改成 <feature>restConnector-2.0</feature> 吗?我认为 1.0 连接器泄漏了 JAX-RS——基本上将它包含在应用程序中——即使你打包了你自己的 JAX-RS 和 CXF 等版本。当这种情况发生时,你会得到 Liberty 的 JAX-RS 版本(它基于CXF 但不允许用户为 API 加载特定于 CXF 的实现 类),甚至可能加载某些实现 类。此外,我认为 restConnector-1.0 功能使用旧版本的 JAX-RS,可能不支持连接和读取超时。

如果迁移到 restConnector-2.0 不起作用,那么我建议明确添加 jaxrs-2.1 功能,然后使用 JAX-RS API 而不是特定于实现的 API。它看起来像:

Client apiClient = ClientBuilder.newBuilder()
                                .connectTimeout(connecTimeout)
                                .readTimeout(readTimeout)
                                .build();
WebTarget target = apiClient.target(uri);
Response response = target.request(MediaType.APPLICATION_JSON)
                          .header("Content-Type", MediaType.APPLICATION_JSON)
                          .get();

希望对您有所帮助!