spring-mvc

How to validate the length of elements inside List using javax.validation.constraints in Spring

南笙酒味 提交于 2020-01-05 06:59:12
问题 How to validate the length of elements inside List using javax.validation.constraints in Spring. Right now @Size is validating on the list size, not on the inside elements. class RequestInputParamaters { @NotNull @NotEmpty @Size(min = 1, max=4) List documentIdentifier_value } 回答1: Try: List<@NotNull @NotEmpty @Size(min = 1, max=4) String> documentIdentifier_value; If using hibernate-validator , you'll need version 6+. Legacy solution: @Valid List<StringWrapper> documentIdentifier_value; where

Spring Security issue with securing URLs dynamically

妖精的绣舞 提交于 2020-01-05 05:51:26
问题 I'm using Spring Security via Spring Boot 1.59 and am having an issue securing URLs dynamically Below is my configure method: @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() //.antMatchers("/home").access("hasAnyRole('ROLE_USER','ROLE_ADMIN')") //.antMatchers("/home3").access("hasRole('ROLE_ADMIN')") .and() .formLogin().loginPage("/login").permitAll() .loginProcessingUrl("/myLogin") .usernameParameter("my_username").passwordParameter("my

Unable to render the JSP using Spring Boot

a 夏天 提交于 2020-01-05 05:48:08
问题 i 'm new in spring boot and i wanted to start with a simple example however nothing seemed to work this my controller: Package controller; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class testController { RequestMapping("view/aboutus") public String greeting(Model model) { model.addAttribute("name", "azertyyyy"); return "aboutus"; }} and this is the jsp view: <%@ page

A function I want to Spring-inject takes varargs. Should I provide an overload that takes a list instead?

不羁的心 提交于 2020-01-05 04:55:18
问题 I have a factory method to box up some order-dependent Things: import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; public class ThingBoxProcessor { public static ThingBox forInputThings(Thing... thingsToProcess) { ThingBox thingBox = new ThingBox(); for (Thing thing : Lists.reverse(ImmutableList.copyOf(thingsToProcess))) { thingBox.store(thing); } return thingBox; } } And I inject it like so: <bean name="Things" class="ThingBoxProcessor" factory-method=

Can't run 'Hello World" Spring MVC code

Deadly 提交于 2020-01-05 04:54:21
问题 I took the following example from Spring's website, trying to understand the basic concepts but so far I've only been struggling with configuration. So here's web.xml: <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <!-- Processes application requests --> <servlet> <servlet-name

Spring MVC mapping with path variable

一笑奈何 提交于 2020-01-05 04:35:08
问题 I have a problem in a big application with rich context, and I spent time to understand why it isn't mapped. So I tried to create simple project and face the same issue :( pom.xml <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://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.springapp</groupId> <artifactId>testMvc</artifactId> <packaging>war

How to configure kafka topic retention policy during creation in spring-mvc?

余生颓废 提交于 2020-01-05 04:33:06
问题 I need to configure retention policy of a particular topic during creation. I tried to look for solution i could only find command level alter command as below ./bin/kafka-topics.sh --zookeeper localhost:2181 --alter --topic my-topic --config retention.ms=1680000 Can someone let me know a way to configure it during creation, something like xml or properties file configuration in spring-mvc. 回答1: Spring Kafka lets you create new topics by declaring @Bean s in your application context. This

Problems fixing java.lang.UnsupportedClassVersionError: Unsupported major.minor version 52

人走茶凉 提交于 2020-01-05 04:30:33
问题 I've read all of the posts about this that I could find, but I can't seem to get past this error to get my maven spring mvc web application working. I just get an HTTP status 500 when i visit localhost or any of the URIs specified in my controllers. From my understanding, the problem occurs because of a higher JDK used at compile time than used at runtime. But it seems to me like all of the references to a JDK or JRE are the same in my case. (1.8) According to this stack overflow post it

Spring RedirectAttributes clears session after redirect

混江龙づ霸主 提交于 2020-01-05 04:30:09
问题 In my Spring i have used RedirectAttributes to display the message after login success or failure and i have one SessionAttribute. I set SessionAttributes in two times first one is when i click the menu i set Object to SessionAttribute and second one is after login success what my problem is the SessionAttribute which i set after login success is not working if i remove the RedirectAttributes means it is working fine. when i searched i found this addFlashAttribute actually stores the

Passing Data from Controller to ChartJS

穿精又带淫゛_ 提交于 2020-01-05 04:28:07
问题 I am trying to pass data from Controller to feed a chart using ChartJS, but when I use a keySet function as labels, the chart is not rendering. This is the Method from Controller: @GetMapping("/reports") public String showDashboard(Model model) { Map<String, Integer> data = new LinkedHashMap<String, Integer>(); data.put("JAVA", 50); data.put("Ruby", 20); data.put("Python", 30); model.addAttribute("data", data); return "reports"; } This is the HTML Code: <pre> <body> <div class="container">