An overview of

In the now almost all the companies have adopted the separation of front and back end development mode, Swagger in API as the online documentation tools, almost is the backend development essential components, the company recently a project, the project started and opens the page of the Swagger, back-end generated a lot of abnormal log, although not affect the normal boot now, however, Every time I see a large number of abnormal logs, I can not tolerate code cleanliness. So TODAY I took some time to solve the following problems. After solving them, I will read the log again. Next I will record the problems and the solutions.

Problem a

Abnormal description: No enum constant org. Springframework. Web. Bind. The annotation. RequestMethod. Get

When the project is started, the following exception is reported in the background log:

why

According to abnormal stack, can see is springfox – swagger – common OperationHttpMethodReader execution. The apply () method is thrown out, analysis of log RequestMethod. Get no corresponding enum, We found the problem by checking the RequestMethod in Controller:

The method methods in the enumeration class are all uppercase, and my code writes method as:

An exception was thrown when the enum type was not matched.

The solution

HttpMethod = “Get”; HttpMethod = uppercase; httpMethod = uppercase; httpMethod = uppercase

Question 2

Abnormal description: Java. Lang. A NumberFormatException: For input string: “”

After the project is up, the interface document can be displayed and used normally after accessing swagger-ui. HTML page, but abnormal logs will appear in the background:

why

See the log, swagger – models in this package AbstractSerializableParameter. GetExample () method when abnormal, and there is a WARN log, Illegal DefaultValue NULL for parameter type INTEGER, meaning that a variable that defaults to an empty string is converted to an INTEGER.

Illegal DefaultValue: Illegal DefaultValue

Long. ValueOf (example) = null; valueOf(example) = null

The solution

Maven package dependencies:

Swagger models is 1.5.20 in mvnRepository.

If you find the latest version 1.6.2, switch to the latest version:

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-boot-starter</artifactId>
    <exclusions>
        <exclusion>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-models</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<! Illegal DefaultValue null for parameter type integer -->
<dependency>
    <groupId>io.swagger</groupId>
    <artifactId>swagger-models</artifactId>
    <version>1.6.2</version>
</dependency>
Copy the code

Take a look at the source:

Found this bug has been fixed, hahaha

One last word

If this article is helpful to you, or inspired, help pay attention to it, your support is the biggest motivation I insist on writing, thank you for your support.

In addition, pay attention to the public number: black lighthouse, focus on Java back-end technology sharing, covering Spring, Spring the Boot, SpringCloud, Docker, Kubernetes middleware technology, etc.