java.lang.NumberFormatException:对于输入字符串:“443,80”
java.lang.NumberFormatException: For input string: "443,80"
我在访问部署在 Kubernetes 容器上的后端 Spring 启动应用程序时遇到以下异常:
java.lang.NumberFormatException: For input string: "443,80"
我所有的服务都在尤里卡注册了:
#Eureka
spring.application.name=app-name
eureka.client.registerWithEureka=true
eureka.client.fetchRegistry=true
eureka.client.serviceUrl.defaultZone=http://app-eureka-dev/eureka
eureka.instance.preferIpAddress=true
eureka.instance.non-secure-port-enabled=true
我的所有请求都通过 ingress/zuul 服务进行路由。
spring.application.name=app-gateway
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=true
eureka.client.serviceUrl.defaultZone=http://app-eureka-dev/eureka
当我们尝试从 Swagger API 访问后端服务时,我遇到了以下异常。
java.lang.NumberFormatException: For input string: "443,80"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.lang.Integer.parseInt(Integer.java:615)
at springfox.documentation.swagger2.web.HostNameProvider.componentsFrom(HostNameProvider.java:72)
at springfox.documentation.swagger2.web.Swagger2Controller.getDocumentation(Swagger2Controller.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod
我正在通过容器名称连接到 eureka 服务,即使我遇到异常。是否需要任何其他配置,因为我们在入口中进行 ssl 卸载,其余应该是容器服务中的纯 http 或不安全调用。
这应该已经用 Springfox 2.7.0 修复了,正如在这个版本的 this GitHub issue and the release notes 中看到的那样。
在Springfox 2.7.0之前,the following code用于确定HostNameProvider
中的端口号:
String port = request.getHeader("X-Forwarded-Port");
if (hasText(port)) {
builder.port(Integer.parseInt(port));
}
所以基本上它使用 X-Forwarded-Port
header 来确定端口号。但是,在您的情况下,它似乎同时通过了 HTTP 和 HTTPS 端口 (443,80
),这显然不是有效整数。
将 springfox-swagger2
依赖项升级到 2.7.0(或更高版本)应该可以解决问题。
当我的 DTO 属性用 @APIModelProerty 注释时,我在 SWAGGER 中遇到了同样的问题。主要是DTO对象中存在Long类型属性,无法将空字符串("")值转换为0时出现问题。
所以,当我在 @APIModelProperty(example = "1", required = "false")
中添加示例 属性 时,它就解决了。
我在访问部署在 Kubernetes 容器上的后端 Spring 启动应用程序时遇到以下异常:
java.lang.NumberFormatException: For input string: "443,80"
我所有的服务都在尤里卡注册了:
#Eureka
spring.application.name=app-name
eureka.client.registerWithEureka=true
eureka.client.fetchRegistry=true
eureka.client.serviceUrl.defaultZone=http://app-eureka-dev/eureka
eureka.instance.preferIpAddress=true
eureka.instance.non-secure-port-enabled=true
我的所有请求都通过 ingress/zuul 服务进行路由。
spring.application.name=app-gateway
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=true
eureka.client.serviceUrl.defaultZone=http://app-eureka-dev/eureka
当我们尝试从 Swagger API 访问后端服务时,我遇到了以下异常。
java.lang.NumberFormatException: For input string: "443,80"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.lang.Integer.parseInt(Integer.java:615)
at springfox.documentation.swagger2.web.HostNameProvider.componentsFrom(HostNameProvider.java:72)
at springfox.documentation.swagger2.web.Swagger2Controller.getDocumentation(Swagger2Controller.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod
我正在通过容器名称连接到 eureka 服务,即使我遇到异常。是否需要任何其他配置,因为我们在入口中进行 ssl 卸载,其余应该是容器服务中的纯 http 或不安全调用。
这应该已经用 Springfox 2.7.0 修复了,正如在这个版本的 this GitHub issue and the release notes 中看到的那样。
在Springfox 2.7.0之前,the following code用于确定HostNameProvider
中的端口号:
String port = request.getHeader("X-Forwarded-Port");
if (hasText(port)) {
builder.port(Integer.parseInt(port));
}
所以基本上它使用 X-Forwarded-Port
header 来确定端口号。但是,在您的情况下,它似乎同时通过了 HTTP 和 HTTPS 端口 (443,80
),这显然不是有效整数。
将 springfox-swagger2
依赖项升级到 2.7.0(或更高版本)应该可以解决问题。
当我的 DTO 属性用 @APIModelProerty 注释时,我在 SWAGGER 中遇到了同样的问题。主要是DTO对象中存在Long类型属性,无法将空字符串("")值转换为0时出现问题。
所以,当我在 @APIModelProperty(example = "1", required = "false")
中添加示例 属性 时,它就解决了。