spring-mvc

Alternate of Spring HandlerMethodSelector.selectMethods

半腔热情 提交于 2020-01-25 07:29:11
问题 I was using Spring 4.2.x HandlerMethodSelector class - now migrating to Spring 5.1.x. Can anyone please help? how can we replace the below code in the latest Spring version? final Set<Method> methods = HandlerMethodSelector.selectMethods(userType, new MethodFilter() { @Override public boolean matches(final Method method) { return hasRequestMappingOverrideAnnotation(method); } }); 回答1: HandlerMethodSelector replaced with MethodIntrospector @deprecated as of Spring 4.2.3, in favor of the

How do I set up unit tests for RepositoryRestController in Spring?

守給你的承諾、 提交于 2020-01-25 06:43:26
问题 I have the following configuration for my unit test for a RepositoryRestController (the MyController class): @RunWith(SpringRunner.class) @WebMvcTest public class MyTest { @Configuration @EnableSpringDataWebSupport static class TestConfiguration { @Bean MyController myController() { //controller construction } } } I can't find any documents online expounding on what sort of config I need to setup to get the tests running correctly. I only stumbled upon EnableSpringDataWebSupport when I was

jdbcTemplate is null and throws null pointer exception [duplicate]

血红的双手。 提交于 2020-01-25 06:05:04
问题 This question already has answers here : Why is my Spring @Autowired field null? (17 answers) Closed 3 years ago . I am new to Spring. I am trying to develop REST API using Spring web MVC. I am trying to fetch some data using JdbcTemplate from my database (MySQL). But when i run the code in the server I am getting 500- Internal Server Error and the stack trace shows java.lang.NullPointerException . When i tried to debug the code i found out that jdbcTemplate variable has null value. I have

jdbcTemplate is null and throws null pointer exception [duplicate]

泄露秘密 提交于 2020-01-25 06:04:06
问题 This question already has answers here : Why is my Spring @Autowired field null? (17 answers) Closed 3 years ago . I am new to Spring. I am trying to develop REST API using Spring web MVC. I am trying to fetch some data using JdbcTemplate from my database (MySQL). But when i run the code in the server I am getting 500- Internal Server Error and the stack trace shows java.lang.NullPointerException . When i tried to debug the code i found out that jdbcTemplate variable has null value. I have

How to create one Controller which returns same Model to arbitrary view (HTML-Form or Ajax)?

浪子不回头ぞ 提交于 2020-01-25 03:45:41
问题 In my classic understanding of the MVC pattern the controller doesn't have to know any implementation details of the view. I want to have a controller which gets triggered by an event (a @RequestMapping ) and returns a model. It's up to the view how to present the Model. The concret use case is adding an item into a shopping cart. I have two views, a simple HTML view and a richer Ajax-View. In my dream scenario both views make a request to the identical URI and hit the only method in my

migrate configuration from dispatcher servlet xml to java class. Do i need both(java class and xml)?

狂风中的少年 提交于 2020-01-25 03:37:25
问题 Following is the code for my dispatcher-servlet.xml and configuration class : Where do i put my db configuration and entity definitions? @Configuration public class MvcConfig extends WebMvcConfigurerAdapter { @Override public void addViewControllers(ViewControllerRegistry registry) { super.addViewControllers(registry); // Default view registry.addViewController("/").setViewName("home"); registry.addViewController("/login").setViewName("login"); registry.addViewController("/home").setViewName(

Authentication request to /j_spring_security_check 404 Error

纵饮孤独 提交于 2020-01-25 02:56:30
问题 With the security configuration below, making a post request to /j_spring_security_check throws a 404 error. Could someone help me point out what I'm doing wrong? security.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:security="http://www.springframework.org/schema/security" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema

Debugging Spring MVC collection binding

旧巷老猫 提交于 2020-01-25 02:33:34
问题 I have a pretty simple user settings form: <form:form method="post" id="fm1" cssClass="fm-v clearfix" commandName="${commandName}" htmlEscape="true"> <div class="row fl-controls-left"> <spring:message code="screen.userSettings.label.timeZone.accesskey" var="timeZoneAccessKey" /> <label for="timeZone" class="fl-label"><spring:message code="screen.userSettings.label.timeZone" /></label> <form:select id="timeZone" path="timeZone" accesskey="${timeZoneAccessKey}"> <form:options items="${user

Debugging Spring MVC collection binding

我是研究僧i 提交于 2020-01-25 02:33:06
问题 I have a pretty simple user settings form: <form:form method="post" id="fm1" cssClass="fm-v clearfix" commandName="${commandName}" htmlEscape="true"> <div class="row fl-controls-left"> <spring:message code="screen.userSettings.label.timeZone.accesskey" var="timeZoneAccessKey" /> <label for="timeZone" class="fl-label"><spring:message code="screen.userSettings.label.timeZone" /></label> <form:select id="timeZone" path="timeZone" accesskey="${timeZoneAccessKey}"> <form:options items="${user

status.setComplete() not clearing the session

穿精又带淫゛_ 提交于 2020-01-25 02:33:05
问题 I am trying to clear a session. Below is a little sample code I wrote to check with SessionStatus . @Controller @SessionAttributes(value={"sessAttr1","sessAttr2","sessAttr3"}) public class SessionController { @RequestMapping(value="index") public ModelAndView populateSession(){ ModelAndView modelView = new ModelAndView("home"); modelView.addObject("sessAttr1","This value is added in a session 1"); modelView.addObject("sessAttr2","This value is added in a session 2"); modelView.addObject(