spring-mvc

Implementing different destinations in applications on the Tomcat server

匆匆过客 提交于 2021-01-28 05:09:24
问题 Earlier this year I developed an implementation of the SAP JCO CustomDestinationProvider for one of my Spring MVC tomcat applications. In my application, I use this implementation to call a BAPI in my SAP R/3 system to retrieve data. I am now working on a second Spring MVC tomcat application that I want to have call a BAPI in my SAP R/3 system to retrieve data. It will be a different BAPI that I will be calling, thus it will be different data that I will be retrieving. Since this is a

Spring REST Docs: how to replace parameters

眉间皱痕 提交于 2021-01-28 04:11:50
问题 In my unit tests we find this.mockMvc .perform(post("/authenticate") .contentType(MediaType.APPLICATION_FORM_URLENCODED) .param("username", "user@example.com") .param("password", "superSecretPassword")) .andExpect(status().isOk()) .andDo(document("preprocessed-request", preprocessRequest(replacePattern(Pattern.compile("superSecretPassword"), "XXX")))); cf. Spring REST Docs documentation This generates build/generated-snippets/preprocessed-request/http-request.adoc with the content [source

Spring MVC OptionalValidatorFactoryBean not found

眉间皱痕 提交于 2021-01-28 03:56:00
问题 Hi I have set up a Spring MVC (4)+Postgresql+JPA app and I encountered the following situation: I want to set up custom queries for my "User" repository so added these lines to the existing (empty) UserRepository: public interface AccountRepository extends JpaRepository<User,Long> { @Query("select u from User u where u.Email = ?1") User findByEmail(String emailAddress); } With the empty Repository, everything is OK with the server, with the verison above I got the following exception on

Spring MVC ModelAttribute as Interface

爷,独闯天下 提交于 2021-01-28 03:29:41
问题 Using a Spring MVC @Controller, how do I have a @RequestMapping endpoint have a @ModelAttribute declared as an interface? I want to have three different forms being posted to the mapping that the underlying classes are all of an interface type. So for example, I can have three different form objects with the action to the following: @RequestMapping(path="/doSomething", method=RequestMethod.POST) public String doSomething(ObjectInterface formInfo) { ... } (Where ObjectInterface is an interface

What is the maven dependency to use Jackson2ObjectMapperBuilderCustomizer? For a spring mvc project

那年仲夏 提交于 2021-01-28 03:26:48
问题 I have a Spring MVC project which does NOT USE spring-boot. Im trying to use Jackson2ObjectMapperBuilderCustomizer in my appConfig class to configure a default date format. I have these two dependencies in already but I'm still getting an error on the ObjectMapper? I am using spring version 4. All the examples for using the Jackson2ObjectMapperBuilderCustomizer are using spring boot which seems to not need need a dependency <dependency> <groupId>com.fasterxml.jackson.core</groupId>

Could not open JPA EntityManager for transaction, using persistence.xml in spring and hibernate

风流意气都作罢 提交于 2021-01-28 03:18:17
问题 I am getting the error that my EntityManager could not be opened: nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is java.lang.NullPointerException root cause org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is java.lang.NullPointerException root cause java.lang.NullPointerException applicationContext.xml:

Spring/Thymeleaf throws “Cannot create a session after the response has been committed” when processing @PostMapping

岁酱吖の 提交于 2021-01-28 03:17:52
问题 I build a Spring MVC application with thymeleaf views and ran into the following problem. I have a page which should process a form and create a new Entity to persist in the database. In my controller class I have two methods for this. First, the @GetMapping to render the page: @GetMapping("/dispo/orderCreate") private String showCreateOrder(Model model) { List<MdUser> userList = service.getUsers(); model.addAttribute("userList", userList); return "/dispo/orderCreate"; } As far as I just

spring @valid doesn't work

China☆狼群 提交于 2021-01-28 02:46:16
问题 i send a POST request of "application/json" type with 「postman」,set the param "phone" to empty string, normally it should print error for annotation "@NotEmpty", however, it didn't print anything and work well. controller: @RequestMapping(value = "verify_smscode", method = RequestMethod.POST) @ResponseBody public ResponseDto verifySmsCode(HttpServletRequest request, @Valid @RequestBody VerifySmsCodeParam params, Errors errors) { if(errors.hasErrors()) { System.out.println("error"); } boolean

Spring MVC ModelAttribute as Interface

两盒软妹~` 提交于 2021-01-28 02:12:18
问题 Using a Spring MVC @Controller, how do I have a @RequestMapping endpoint have a @ModelAttribute declared as an interface? I want to have three different forms being posted to the mapping that the underlying classes are all of an interface type. So for example, I can have three different form objects with the action to the following: @RequestMapping(path="/doSomething", method=RequestMethod.POST) public String doSomething(ObjectInterface formInfo) { ... } (Where ObjectInterface is an interface

How can I hook into Spring's @RequestBody argument resolving to resolve my own argument using the body of the request

元气小坏坏 提交于 2021-01-28 01:15:29
问题 In the process of developing our app, we found ourselves doing something like this in our controller: @RequestMapping(value = "foo", method = RequestMethod.POST) @ResponseBody public SimpleMasterWidget doStuff(@RequestBody ClientData clientData, ServerData serverData) throws Exception { pushClientDataToServerData(clientData, serverData); //stuff specific to this operation on the serverData return whatever; } The pushClientDataToServerData(clientData, serverData); call gets duplicated in every