spring-mvc

Is NotNull needed on Kotlin?

浪子不回头ぞ 提交于 2020-05-27 05:33:50
问题 I have a class: class User( var name: String ) And a mapped post request: @PostMapping("/user") fun test(@Valid @RequestBody user: User) { //... } What if a client will send a JSON of a user with name: null ? Will it be rejected by the MVC Validator or an exception will be throwed? Should I annotate name with @NotNull ? Unfortunately, I cannot check that because only can write tests (it is not available to create User(null) ). 回答1: You can avoid using @NotNull , as it'll never get triggered

Is NotNull needed on Kotlin?

我怕爱的太早我们不能终老 提交于 2020-05-27 05:33:33
问题 I have a class: class User( var name: String ) And a mapped post request: @PostMapping("/user") fun test(@Valid @RequestBody user: User) { //... } What if a client will send a JSON of a user with name: null ? Will it be rejected by the MVC Validator or an exception will be throwed? Should I annotate name with @NotNull ? Unfortunately, I cannot check that because only can write tests (it is not available to create User(null) ). 回答1: You can avoid using @NotNull , as it'll never get triggered

Spring Boot intercept all exception handlers

北慕城南 提交于 2020-05-26 19:20:44
问题 I am trying to perform some common logic that applies to all my @ExceptionHandler s in code. I know I can write a HandlerInterceptor to intercept happy paths. But I would like to hook into the exception handling lifecycle so that I can execute some common logic such as logging, before the error response is rendered. Is there anyway to do this in Spring Boot / Spring MVC? I would like to avoid having to write a servlet filter for this purpose if possible. 回答1: There is a way with

Spring Boot intercept all exception handlers

早过忘川 提交于 2020-05-26 19:19:30
问题 I am trying to perform some common logic that applies to all my @ExceptionHandler s in code. I know I can write a HandlerInterceptor to intercept happy paths. But I would like to hook into the exception handling lifecycle so that I can execute some common logic such as logging, before the error response is rendered. Is there anyway to do this in Spring Boot / Spring MVC? I would like to avoid having to write a servlet filter for this purpose if possible. 回答1: There is a way with

spring boot return string instead of .html file

拟墨画扇 提交于 2020-05-26 00:20:32
问题 I tried to run spring boot application, that will return me the HTML static file on the static folder, the problem was: every time I load the page: 127.0.0.1 I get the String "bakara" and not the HTML file bakara.html. and when I load 127.0.0.1/bakara.html I get the bakara.html file pom.xml: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http:/

spring boot return string instead of .html file

℡╲_俬逩灬. 提交于 2020-05-26 00:17:38
问题 I tried to run spring boot application, that will return me the HTML static file on the static folder, the problem was: every time I load the page: 127.0.0.1 I get the String "bakara" and not the HTML file bakara.html. and when I load 127.0.0.1/bakara.html I get the bakara.html file pom.xml: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http:/

spring boot return string instead of .html file

自闭症网瘾萝莉.ら 提交于 2020-05-26 00:15:24
问题 I tried to run spring boot application, that will return me the HTML static file on the static folder, the problem was: every time I load the page: 127.0.0.1 I get the String "bakara" and not the HTML file bakara.html. and when I load 127.0.0.1/bakara.html I get the bakara.html file pom.xml: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http:/

404 Exception not handled in Spring ControllerAdvice

半世苍凉 提交于 2020-05-25 20:20:46
问题 I have a simple Spring MVC application in which I want to handle all the unmapped urls using @ControllerAdvice . Here is the controller: @ControllerAdvice public class ExceptionHandlerController { @ResponseStatus(HttpStatus.NOT_FOUND) @ExceptionHandler(NoHandlerFoundException.class) public String handle404() { return "exceptions/404page"; } } Still, every time get Whitelabel Error Page. I tried using RuntimeException.class , HttpStatus.BAD_REQUEST and extending the class with

Spring Boot Application immediately shuts down after starting

让人想犯罪 __ 提交于 2020-05-25 04:57:38
问题 I am working currently on a project which includes the Spring Framework. Everything is working as aspect but there is one problem. When I try to start my application onto my laptop it immediately shuts down after startup. It is working on every other machine, so this problem occurs only on my laptop. Maybe you got an idea what could force this problem ? I am working with IntelliJ and I haven´t found any solutions for this problem. PC Specs Laptop is a AsusN550JK( modified RAM and SSD) Intel

Errors in pom.xml with dependencies (Missing artifact…)

拜拜、爱过 提交于 2020-05-25 03:31:25
问题 A friend has passed me a Maven project that I'm trying to run locally in my computer. All that I have done in Eclipse, I selected: File -> Import -> Existing Maven Projects After that, the project showed me 4 errors in my pom.xml (Missing artifact..): I tried removing the content of .m2 folder and then in Eclipse I clicked on my project and chose "Run as" -> "Maven clean" and then "Run as" -> "Maven install". But I still have the same errors. I'm new with Spring so I dont know what else to do