spring-mvc

Using Spring mockMvc to test optional path variables

吃可爱长大的小学妹 提交于 2020-01-13 08:08:10
问题 I have a method in Spring MVC with optional path variable. I am trying to test it for a scenario when optional path variable is not provided. Snippet from Controller, resource URI to invoke- @RequestMapping(value = "/some/uri/{foo}/{bar}", method = RequestMethod.PUT) public <T> ResponseEntity<T> someMethod(@PathVariable("foo") String foo, @PathVariable(value = "bar", required = false) String bar) { LOGGER.info("foo: {}, bar: {}", foo, bar); } Snippet from my test using MockMvc- //inject

Apache Tiles alternatives

≯℡__Kan透↙ 提交于 2020-01-13 07:53:09
问题 I am writing a Spring MVC application and looking for a way to do layouts in views. The only option that i see is Apache Tiles, which i have used before and know how painful it is to maintain its configuration. Are there any good alternatives? I looked at SiteMesh and Spring Surf both seem to be dormant. 回答1: I faced the same dilemma about a month ago. I have been a seasoned developer using apache tiles, and I wanted to try something different. I did some research and found that Spring MVC

Adding custom error messages for validation in Spring-MVC

有些话、适合烂在心里 提交于 2020-01-13 07:29:07
问题 I am using Spring-MVC and I would like to do validation tests in backend. Currently I am able to perform the tests, redirect properly to the link. But I am only unable to add custom error messages incase there is a problem, Example : "Firstname is empty". I tried using the ValidationMessages_en_EN.properties file in WEB-INF, but that also didn't help. I am posting my code, kindly let me know where I am going wrong : COntroller : @Controller public class PersonController { @RequestMapping

JavaTypeDescriptorRegistry - Could not find matching type descriptor for requested Java class

时光怂恿深爱的人放手 提交于 2020-01-13 07:26:18
问题 I have a project running with no problem except this warning message: WARN org.hibernate.type.descriptor.java.JavaTypeDescriptorRegistry - Could not find matching type descriptor for requested Java class [java.util.List]; using fallback enviroment Why am I getting this message? How can I disable it? I'm using: spring webmvc 4.2.1 hibernate-core 5.0.1 This message appears since I'm using JPA 2.1 AttributeConverter. 回答1: You get this warning if the type your converter is supposed to convert

Using HashMap in dropdown list in Thymeleaf

℡╲_俬逩灬. 提交于 2020-01-13 05:57:25
问题 In my controller I am setting a hashmap @ModelAttribute("clientImpMap") public Map<String,String> populateClientImpMap() throws MalformedURLException, IOException { Map<String,String> clientImpMap = new HashMap<String,String> (); clientImpMap.put("1","High"); clientImpMap.put("2","Low"); return clientImpMap; } Now I want to populate this hashmap using Thymeleaf tags .How to do it? Using core Spring-mvc tags I can do this <td>Client Importance :</td> <td><form:select path="personBean

Moving to Spring Boot 1.5.1 and OAuth2 + JWT token - Error 401 Unauthorized

旧街凉风 提交于 2020-01-13 05:36:07
问题 I'm trying to move my project to Spring Boot 1.5.1 and right now my configuration of Outh2 + JWT tokens stopped working. Right now I receive 401 error while performing a following test: RestTemplate restTemplate = new RestTemplate(); CreateDecisionRequest decisionRequest = new CreateDecisionRequest(name, description, url, imageUrl, parentDecisionId, tenantId); HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); headers.add(SecurityTestUtils

How pass params to Thymeleaf Ajax Fragment

…衆ロ難τιáo~ 提交于 2020-01-13 04:52:28
问题 I have a Spring MVC controller that returns the name of a thymeleaf fragment to view resolver bean. The problem is that this fragment needs a url as a parameter. Here I put the fragment: <!-- A fragment with wrapper form for basic personal information fragment --> <th:block th:fragment="form-basic(url)"> <form role="form" th:action="${url}" method="post" th:object="${user}"> <th:block th:replace="admin/fragments/alerts::form-errors"></th:block> <th:block th:include="this::basic" th:remove=

Spring Boot Thymeleaf Layout Dialect Not Working

巧了我就是萌 提交于 2020-01-13 04:32:27
问题 I just created a new Spring Boot v1.5 project and facing issue where Thymeleaf Layout Dialect is not working. I have the dependencies in my build.gradle and its on the classpath. compile group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect', version: '2.1.2' I have the following layout file <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"> <head> <meta charset="UTF-8" /> <title

Spring MVC best way to populate drop down list - properties file?

给你一囗甜甜゛ 提交于 2020-01-13 02:43:28
问题 I want to populate a drop down list and I do not want to keep going to the database. I was thinking to have my country list or language list in a properties file. That way I could read it in, and then assign that to a variable. I could then return that through the ModelAndView type. Is this a good approach? I am not sure how else to store static data. I do not want to keep it in a class because it will be harder to update it if there needs to be a change. 回答1: got an answer! If I got a list

Why PRG pattern rather than others?

前提是你 提交于 2020-01-13 02:13:31
问题 I need to prevent duplicate form submissions for my customer's website. we need some form data from user for order confirm page. we use load balancing for web server. Approach 1 : Post/Redirect/Get (PRG pattern : http://en.wikipedia.org/wiki/Post/Redirect/Get) I was trying to use PRG pattern at first. in this case, I think I need to deal with session(or spring flashmap) across multiple web server. Approach 2 : Disable refresh on client. one of my colleague suggested this approach. Approach 3