spring-mvc

Thymeleaf + Spring Boot: Error Page

我们两清 提交于 2021-01-05 07:00:29
问题 I have a basic SpringBoot app. using Spring Initializer, embedded Tomcat, Thymeleaf template engine, and package as an executable JAR file I want to redirect all the application Errors to a common page. I've created this controller: @Controller public class AppErrorController implements ErrorController { /** * Error Attributes in the Application */ private ErrorAttributes errorAttributes; private final static String ERROR_PATH = "/error"; /** * Controller for the Error Controller * @param

Thymeleaf + Spring Boot: Error Page

怎甘沉沦 提交于 2021-01-05 06:55:13
问题 I have a basic SpringBoot app. using Spring Initializer, embedded Tomcat, Thymeleaf template engine, and package as an executable JAR file I want to redirect all the application Errors to a common page. I've created this controller: @Controller public class AppErrorController implements ErrorController { /** * Error Attributes in the Application */ private ErrorAttributes errorAttributes; private final static String ERROR_PATH = "/error"; /** * Controller for the Error Controller * @param

how do I throw a error on unknown fields in json request to spring restapi

让人想犯罪 __ 提交于 2021-01-03 16:58:55
问题 I have a spring rest api which gets json data and binds to a pojo GetData. Whenever i recieve unknown fields it doesnt fail or throw any exception. My requirement here is it should throw a error when it receives unknown fields in json data. public ResponseEntity<Error> saveLocation(@Valid @RequestBody GetData getdata,BindingResult bindingResults) { Below is my Pojo GetData public class GetData{ @JsonProperty("deviceID") @Pattern(regexp="^[\\p{Alnum}][-\\p{Alnum}\\p{L}]+[\\p{Alnum}]$",message

Custom controller with Spring Data REST hide default endpoints

二次信任 提交于 2021-01-01 07:21:13
问题 I'm using Spring Boot, Spring Data REST, Spring HATEOAS, Hibernate, JPA. I'm using extensively Spring Data REST in my application and I expose all Repositories of my entities. Unfortunately there are some particular cases that are not so easy to manage. One of that is this: I've a custom controller: @Api(tags = "CreditTransfer Entity") @RepositoryRestController @RequestMapping(path = "/api/v1") @PreAuthorize("isAuthenticated()") public class CreditTransferController { @RequestMapping(method =

Custom controller with Spring Data REST hide default endpoints

北战南征 提交于 2021-01-01 07:19:17
问题 I'm using Spring Boot, Spring Data REST, Spring HATEOAS, Hibernate, JPA. I'm using extensively Spring Data REST in my application and I expose all Repositories of my entities. Unfortunately there are some particular cases that are not so easy to manage. One of that is this: I've a custom controller: @Api(tags = "CreditTransfer Entity") @RepositoryRestController @RequestMapping(path = "/api/v1") @PreAuthorize("isAuthenticated()") public class CreditTransferController { @RequestMapping(method =

Specifying @RequestHeader once for all controllers in Spring Boot app

你。 提交于 2020-12-30 08:57:31
问题 I have a Spring Boot app with multiple controllers serving various REST methods. Each of the methods require that the same header parameter be defined. Is there a way to specify something like the following one time for all controller methods? public ResponseEntity get(@RequestHeader(value="NAME", required = true) String name, ...) { ... } Thanks. 回答1: You can probably achieve this using @ModelAttribute , like this: public class Something { private name; //... } @ModelAttribute("something")

RestAssuredMockMvc Connection to http://localhost:8080 refused

我怕爱的太早我们不能终老 提交于 2020-12-30 06:48:05
问题 I developed a Spring MVC webapp with rest methods. I would love to use RestAssured to create JUnit test classes. From the documentation it looks really simple to do but I'm having some problem instead. Basically I want to use it to avoid a runtime Tomcat instance but the problem is that when I execute the JUnit test class I obtain the following exception: org.apache.http.conn.HttpHostConnectException: Connection to http://localhost:8082 refused ... Caused by: java.net.ConnectException:

RestAssuredMockMvc Connection to http://localhost:8080 refused

做~自己de王妃 提交于 2020-12-30 06:47:55
问题 I developed a Spring MVC webapp with rest methods. I would love to use RestAssured to create JUnit test classes. From the documentation it looks really simple to do but I'm having some problem instead. Basically I want to use it to avoid a runtime Tomcat instance but the problem is that when I execute the JUnit test class I obtain the following exception: org.apache.http.conn.HttpHostConnectException: Connection to http://localhost:8082 refused ... Caused by: java.net.ConnectException:

RestAssuredMockMvc Connection to http://localhost:8080 refused

北战南征 提交于 2020-12-30 06:47:45
问题 I developed a Spring MVC webapp with rest methods. I would love to use RestAssured to create JUnit test classes. From the documentation it looks really simple to do but I'm having some problem instead. Basically I want to use it to avoid a runtime Tomcat instance but the problem is that when I execute the JUnit test class I obtain the following exception: org.apache.http.conn.HttpHostConnectException: Connection to http://localhost:8082 refused ... Caused by: java.net.ConnectException:

Spring Thymeleaf Bootstrap CSS

一笑奈何 提交于 2020-12-29 09:19:27
问题 I'm trying to use Bootstrap CSS with my Spring + Security + Thymeleaf web application. The CSS gets picked up the by my custom login screen and everything is fine - all styles are applied. However, when I progress from the login screen to the next screen for some reason my html page is not picking up the CSS file and the styles are not being applied. Can someone assist? Below are the relevant files: Login html file (which is working fine): <!DOCTYPE html> <html lang="en" xmlns="http://www.w3