Skip to content
Advertisement

Tag: spring-mvc

Expecting exception during MockMVC.perform in JUnit5

This may be a repeated question. But I have gone through some 10-15 related posts and associated responses which have not resolved my issue. The issue that I am facing is as here below I have a SpringRest controller class with custom ApplicationException. I have written a Junit for my controller and here below is the snippet where I am

Life span and injection of @SessionAttributes object in Spring MVC

I’m unclear on some subtleties of using @SessionAttributes in Spring MVC via Spring Boot 2.3.3.RELEASE. I have two controllers, Step1Controller and Step2Controller. Both controllers use @SessionAttributes(“foobar”) at the class level. Step1Controller during its request handling for @PostMapping adds a special FooBar instance to the model using model.addAttribute(“foobar”, new FooBar(“foo”, “bar”)). Step2Controller, invoked under a completely independent HTTP POST, picks up

Swagger OpenAPI 3.0 – Springdoc – GroupedOpenApi not working in Spring MVC

My Application is Sping MVC not boot. I’m using springdoc-openapi-ui 1.4.4 also, I added the following imports to one of my @configuration class; and implement the beans as below But when I try http://localhost:8080/MyApp/v3/api-docs/user gives me 404. but I get all the APIs listed in http://localhost:8080/MyApp/v3/api-docs Also it comes in http://www.onlykalu.com:81/MyApp/swagger-ui/index.html?configUrl=/MyApp/v3/api-docs/swagger-config also without definition drop down. if I add to

Spring Boot 2.x Servlet Path is ignored in test

in my application-test.properties I have this server.servlet.context-path=/api It works totally fine when I run the application and test it with postman. But as soon as I run my tests it swallows the part /api of the path. So basically how it should be localhost:8080/api/testUrl but the controller is only available here localhost:8080/testUrl My Testclass head no setup behavior implemented. and

How to format the date time correctly in Spring Boot?

I would like to know how to format the date time correctly? The result is Localdatetime yyyy-MM-ddTHH:mm. Could you advise how to solve? I’m using Java 11, and does it because @JsonFormat not support @RequestParam? Controller: Entity: Answer Since you are using Spring-boot , I’m also assuming you are using java8 . In any case try using java8 time api

Why is @Validated required for validating Spring controller request parameters?

With the following validation setup in an annotated MVC controller: @Validated on the controller is required for the method parameter since it’s not a “complex” object. In comparison, the @Valid annotation on the setOther method works without the @Validated annotation. Why is @Validated required? Why not enable it by default? Is there a cost to its use? edit Note that

Advertisement