Home>

The problem is that when I run the Spring application on my laptop, everything works fine, and when I transfer it to the server in Tomcat, the interesting begins. The first request with FormData goes through and is processed normally, everything is entered into the database, but subsequent requests fail with a 500 error without a message.

Here is an example of an error response:

{
    "timestamp": "2021-12-02T22: 53: 08.872 + 00: 00",
    "status": 500,
    "error": "Internal Server Error",
    "message": "",
    "path": "/hustle /api /catalog /add"
}

And here is the controller method that handles the request:

@RequestMapping (
    value= ["add"],
    method= [RequestMethod.POST],
    consumes= ["multipart /form-data"]
)
fun add (
    @RequestParam ("image") file: MultipartFile,
    @RequestParam ("name") name: String,
    @RequestParam ("longName") longName: String,
    @RequestParam ("description") description: String,
    @RequestParam ("price") price: Int
): DataWrapper <
Any >
 {
    return try {
        //write to the database
    } catch (ex: Exception) {
        //error output (not 500)
    }
}

As for the project settings, they are completely default, with the exception of a couple of points:

Added 3 lines to the settings so that the file can be loaded

  1. spring.servlet.multipart.max-file-size= 10MB
  2. spring.servlet.multipart.max-request-size10MB
  3. spring.servlet.multipart.enabled= tru *

Added spring-boot-starter-web dependencies and removed request size limitation in Tomcat settings.

Everything would be better if it didn't work at all, and the fact that it works the first time is confusing.

Thanks in advance for your help.

500 is the http code. The whole error of the spring is written on the server side, look in the logs there with what it crashes and copy the text here.

Mira2021-12-05 00:54:09

@Mira, supplemented the answer with an error message

LeonSolya2021-12-05 00:54:09

Okay, a fair minus, this is a jamb of tomato, and if I immediately thought of pulling out the logs from the server, I would fix everything myself

LeonSolya2021-12-05 00:54:09

normal question you have :)

Mira2021-12-05 00:54:09