spring-mvc

Work around Hibernate's errors in multithreaded applications

≯℡__Kan透↙ 提交于 2020-01-16 05:18:25
问题 Because of all the problems we can meet when trying to use Hibernate in a multithreaded application (1st clue, 2nd clue, 3rd clue, etc.), I was thinking of another solution: implementing the logical part within a classic Controller , and simply call it from my thread using URL.openConnection() . In other words, instead of doing something like this: MyThread.java public class MyThread implements Runnable { @Override public void run() { // do some great stuff with Hibernate } } Anywhere.java

Why my rest endpoint receives empty dto

烈酒焚心 提交于 2020-01-16 04:54:06
问题 I am trying to post pojo to rest endpoint with RestTemplate Dto dto = new Dto(); dto.setPhone("12313"); RestTemplate restTemplate = new RestTemplate(); restTemplate.postForObject(new URI("http://localhost:8080/test"), dto, Dto.class); but I receive empty dto on the server side @RequestMapping(value = "/test") @ResponseBody public DTO test123(DTO dto) { System.out.println(dto.getPhone()); // empty return dto; } The Dto is simple pojo public class Dto { private String phone; public String

JSR-303 and Spring MVC Binding Result

血红的双手。 提交于 2020-01-16 04:09:12
问题 I'm trying to figure out how to get localized error messages when a validation error occurs. My domain object looks like this: @RooJavaBean @RooToString @RooEntity public class Lead { @Email(message = "{email_error_message}") String emailAddress; } My Controller looks like this: @RequestMapping(method=RequestMethod.POST) public @ResponseBody String create(@Valid Lead lead, BindingResult result) { log.debug("In POST!"); if(result.hasErrors()) { FieldError fieldError = result.getFieldError(

How to map multiple parameter names to POJO when binding spring mvc command objects

二次信任 提交于 2020-01-16 03:59:08
问题 My question is actually a spin-off of this question as seen here... so it might help to check that thread before proceeding. In my Spring Boot project, I have two entities Sender and Recipient which represent a Customer and pretty much have the same fields, so I make them extend the base class Customer ; Customer base class; @MappedSuperclass public class Customer extends AuditableEntity { @Column(name = "firstname") private String firstname; @Transient private CustomerRole role; public

NoSuchBeanDefinitionException using @Autowired in spring test

試著忘記壹切 提交于 2020-01-16 02:51:27
问题 I have spring-mvc-security project and I am trying create junit test from JavaConfig for one of the controllers, but when i use @Autowired i get exception: Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.secure.service.face.UserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true

How to handle 404 exception invoked by ajax, Spring MVC 3.2, @ControllerAdvice

我与影子孤独终老i 提交于 2020-01-16 00:53:11
问题 In Spring MVC, if I submit web form using normal submit I can handle 404 exception in web.xml as <error-page> <error-code>404</error-code> <location>404.jsp</location> </error-page> <error-page> <exception-type>java.lang.Exception</exception-type> <location>404.jsp</location> </error-page> But how to intercept 404 error from ajax call (probably using @ControllerAdvice ) and pass custom exception to xhr.responseText in jquery ? 回答1: You could use a default controller for unmapped requests, and

Spring rest - custom header validation on method level [closed]

。_饼干妹妹 提交于 2020-01-16 00:39:32
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 6 years ago . I am working on spring based rest service and looking for the wy to validate custom request header for some methods and not the others. Could You advice what is the best way to achieve this please? Is it possible to achieve it e.g. via custom annotations?: @RequestMapping

Spring project template not showing templates

梦想与她 提交于 2020-01-16 00:27:10
问题 I downloaded Spring STS 3.6.1 and I tried to create a spring MVC project, but the templates are missing: As you can see it says requires downloading! I pressed Refresh several times and restarted STS, but I still can't get it to list the templates. When I pressed configure templates: I'm working on my home laptop running Windows 7. I'm able to access Eclipse market place and I'm not behind a proxy. I tried another laptop also running Windows 7, but in vain. What is wrong? 回答1: As user

Spring project template not showing templates

元气小坏坏 提交于 2020-01-16 00:25:57
问题 I downloaded Spring STS 3.6.1 and I tried to create a spring MVC project, but the templates are missing: As you can see it says requires downloading! I pressed Refresh several times and restarted STS, but I still can't get it to list the templates. When I pressed configure templates: I'm working on my home laptop running Windows 7. I'm able to access Eclipse market place and I'm not behind a proxy. I tried another laptop also running Windows 7, but in vain. What is wrong? 回答1: As user

How to create a client app for a RESTful service from wadl?

淺唱寂寞╮ 提交于 2020-01-16 00:08:34
问题 Given an application.wadl file, how do I generate Client app (Spring or any) and domain objects from a wadl file? I tried : wadl2java https://genologics.com/files/permanent/API/2.5/application.wadl WADLToJava Error: java.lang.IllegalStateException: Single WADL resources element is expected 回答1: This is my findings by reviewing the source-code: As SourceGenerator.java, wadltojava is trying to get the "resources" element from the "application" element and expects it to be one only. private void