spring-mvc

Spring MVC Handler Interceptor does not run

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-13 11:16:32
问题 I have following interceptor class : package cz.coffeeexperts.feedback.server.web.interceptors; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; public class RestAuthorizationInterceptor extends HandlerInterceptorAdapter { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { System.out.println("fuu");

Spring MVC Handler Interceptor does not run

£可爱£侵袭症+ 提交于 2020-01-13 11:16:30
问题 I have following interceptor class : package cz.coffeeexperts.feedback.server.web.interceptors; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; public class RestAuthorizationInterceptor extends HandlerInterceptorAdapter { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { System.out.println("fuu");

org.springframework.validation.BeanPropertyBindingResult Exception

早过忘川 提交于 2020-01-13 11:09:18
问题 Hi I am a new to spring framework. I have done a small example where I tried to validate my input field using spring validation api. This is the code @RequestMapping(value = "/applicationFormSubmit", method = RequestMethod.POST) public String insertdata( @ModelAttribute("applicationForm") @Valid ApplicationFormBean applicationFormBean, @RequestParam("file") MultipartFile file, BindingResult result,Model model) { if(result.hasErrors()) { return "applicationForm"; } try { Blob blob = Hibernate

the request sent by the client was syntactically incorrect when sending post requests

依然范特西╮ 提交于 2020-01-13 10:52:58
问题 The method in myController looks like this @RequestMapping(value="/{processId}/dependents", method=RequestMethod.POST,consumes="application/json") @ResponseBody public Dependents postdependent(@ModelAttribute ProcessContext process,@RequestBody Dependent dependent) { return process.getDependents().addDependent(dependent); } My gets and delete work perfectly. But whenever I do a post I am getting the request sent by the client was syntactically incorrect. JSON for post request: "{ 'dependentId

Spring MVC can't handle 404 from Resource Handler?

我们两清 提交于 2020-01-13 10:37:31
问题 I'm using Spring MVC 4.3.11.RELEASE and have a vanilla resource handler for static resources. It's working fine - for resources that exist. However if not, it appears to return a 404 to the DispatcherServlet which is happy with that response since it found a handler. I've got ControllerAdvice for NoHandlerFoundException which works fine for controllers but isn't meant to handle this case. So Spring MVC punts completely and I get the nasty Tomcat 404 response. I can find no way to configure

Run a timer task on a specific day (1st of every month) using Spring

我的未来我决定 提交于 2020-01-13 10:26:48
问题 We have a requirement of running a job on 1st of every month (time: 00:00:00 AM) exactly. We are using Spring framework's ScheduledTimerTask to schedule jobs using delay and period properties. This class doesn't support running a job on specific date. Can somebody suggest, how we can solve that problem using Spring and Java technology? 回答1: If you don't have to run this job on a single node in a cluster you can use Spring Task, see: http://docs.spring.io/spring/docs/current/spring-framework

Trying to write junit test in Spring with JavaConfig

让人想犯罪 __ 提交于 2020-01-13 09:43:07
问题 I am trying to write a junit test for my example project but don't know how to access the ApplicationContext in the jUnit Test: Here is the main class of the project that works: public static void main(String[] args) { // in this setup, both the main(String[]) method and the JUnit method both specify that ApplicationContext context = new AnnotationConfigApplicationContext( HelloWorldConfiguration.class ); MessageService mService = context.getBean(MessageService.class); HelloWorld helloWorld =

How to get PDF content (served from a Spring MVC controller method) to appear in a new window

风格不统一 提交于 2020-01-13 09:01:49
问题 I am a newbie with Spring MVC but I'm quite impressed with its capabilities. I am using 3.1.0-RELEASE and I have to show a PDF in response to form:form submission. Here is the (small) code I wrote in the controller: @RequestMapping(value = "new_product", method = RequestMethod.POST, params = "print") @ResponseBody public void saveAndShowPDF(ModelMap map, ShippingRequestInfo requestInfo, HttpServletRequest request, HttpServletResponse httpServletResponse) throws IOException {

Spring @ControllerAdvice vs ErrorController

最后都变了- 提交于 2020-01-13 08:29:29
问题 In my REST service app, I am planning to create a @ControllerAdvice class to catch controller thrown exceptions and return ResponseEntity objects according to the error type. But I already have a @RestController class implementing the ErrorController interface to catch all exceptions. Do these two interfere in any manner? In which cases will ErrorController be called when @ControllerAdvice exists? Edit: The ErrorController code as requested @RestController public class ControllerCustomError

Using Spring mockMvc to test optional path variables

谁说我不能喝 提交于 2020-01-13 08:08:37
问题 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