Spring Boot can’t autowire @ConfigurationProperties

This is expected as @ConfigurationProperties does not make a class a Spring Component. Mark the class with @Component and it should work. Note that a class can only be injected if it is a Component. Edit: From Spring 2.2+ (Reference) @ConfigurationProperties scanning Classes annotated with @ConfigurationProperties can now be found via classpath scanning as an … Read more

org.apache.catalina.connector.ClientAbortException: java.io.IOException: APR error: -32

Most likely, your server is taking too long to respond and the client is getting bored and closing the connection. A bit more explanation: tomcat receives a request on a connection and tries to fulfill it. Imagine this takes 3 minutes, now, if the client has a timeout of say 2 minutes, it will close … Read more

Does Spring create new thread per request in rest controllers?

It’s blocking in the sense that it blocks one thread: the thread taken out of the pool of threads by the servlet container (Tomcat, Jetty, etc., not Spring) to handle your request. Fortunately, many threads are used concurrently to handle requests, otherwise the performance of any Java web application would be dramatic. If you have, … Read more

upload file springboot Required request part ‘file’ is not present

This is how your request in Postman should look like: My sample code: application.properties #max file and request size spring.http.multipart.max-file-size=10MB spring.http.multipart.max-request-size=11MB Main Application Class: Application.java import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } Rest controller class: import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestBody; … Read more

Could not verify the provided CSRF token because your session was not found in spring security

According to spring.io: When should you use CSRF protection? Our recommendation is to use CSRF protection for any request that could be processed by a browser by normal users. If you are only creating a service that is used by non-browser clients, you will likely want to disable CSRF protection. So to disable it: @Configuration … Read more

Return HTTP 204 on null with spring @RestController

You can use the @ResponseStatus annotation. This way you can have a void method and you don’t have to build a ResponseEntity. @DeleteMapping(value = HERO_MAPPING) @ResponseStatus(value = HttpStatus.NO_CONTENT) public void delete(@PathVariable Long heroId) { heroService.delete(heroId); } BTW returning 200 when the object exists and 204 otherwise it’s a bit unusual regarding API REST design. It’s … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)