spring-mvc

Hosting a single page application with spring boot

穿精又带淫゛_ 提交于 2020-01-04 03:52:41
问题 So I am trying to host a Single Page Application alongside a normal REST API with spring. What this means is that all requests that goes to the normal /api/ endpoints should be handled by the respective controller and all other requests should be directed to the resources in the folder /static/built I have gotten this to work by catching all NoHandlerFoundExceptions and redirecting to either the js file or the html file. And then used a WebMvcConfigurer to map the static content. But this all

Omit ModelAttribute from view

一世执手 提交于 2020-01-04 03:27:10
问题 I have a rest application that returns json/xml. I use jackson and jaxb for conversion. Some methods need to accept a query_string. I've used @ModelAttribute to map the query_string into an object, but this forces the object into my view. I do not want the object to appear in the view. I think I need to use something other than @ModelAttribute, but I can't figure out how to do the binding, but not modify the view. If I omit @ModelAttribute annotation, the object appears in the view as the

How to access the one Web application Context in another Web application Context

╄→гoц情女王★ 提交于 2020-01-04 02:19:36
问题 I have deployed two WAR's in a Tomcat6 server, Say for example WAR-A , WAR-B in Context-A and Context-B respectively. I've stored some data in Context-A , and I want to read that data in Context-B . I have gone through the net and got some way to acheive it. I make the session ID of Context-A available for all the contexts by cookies. And I have set the crossContext = true in server.xml too. But when I do serveltContext.getContext("Context-A"); in Context-B it's returning null . 回答1: The

Spring Boot : Handler dispatch failed; nested exception is java.lang.NoSuchMethodError

倾然丶 夕夏残阳落幕 提交于 2020-01-04 02:19:16
问题 I encountered this exception when I try to do a rest call to a spring boot services. what causes this exception? Message Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.getResponseStatus()Lorg/springframework/http/HttpStatus; Description The server encountered an unexpected condition that prevented it from fulfilling the request. Exception org.springframework.web.util

Spring Boot Multi-Module maven project repackage failed

老子叫甜甜 提交于 2020-01-04 02:06:12
问题 I'm currently following John Thompson's Spring Framework Beginner to Guru course. I follow his step by step procedures on creating multi module maven project for spring pet clinic on spring boot. When I clicked package on my root module it says repackaged failed, unable to find main class. <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> <configuration>

Map checkboxes to List using Sprint Boot and Thymeleaf

穿精又带淫゛_ 提交于 2020-01-04 02:02:06
问题 I have a Spring Boot 1.3.0 app that uses Thymeleaf . I have a form on a page that allows a user to upload a file. I would like to add some checkboxes also return back to my controller. I have not found a good example how to do checkboxes this way. I think I have to define a list in my model, and let Thymeleaf display all the check boxes, but I have not been able to make it work. Here is my controller: @Controller public class CustomerDataController { private static final String SEARCH_TYPES =

can i set the url before returning the ModelAndView?

可紊 提交于 2020-01-04 01:58:32
问题 is it possible to set your url before returning your model? For example, my current url is http://localhost/home.html at my homecontroller, I return a modelandview for another page, for example ModelAndView model = new ModelAndView("contact"); model.addObject("contactNo", "12345"); return model; then after returning the model, my contact.jsp has been loaded to my browser but it's url is still http://localhost/home.html, I want to change it to http://localhost/contact.html, how can i able to

add a filter with urlMapping on spring boot

夙愿已清 提交于 2020-01-04 01:50:15
问题 I have a class like this @WebFilter(urlPatterns={"/message/*","/private_message"}) @Component public class TokenAuthenticationFilter extends FilterRegistrationBean { and I thought that Spring Boot would respect the urlPatterns setted, but for some reason, every request gets to this filter. I think I may be doing something wrong. Also, I'm not using Spring Security 回答1: You're mixing use of @WebFilter and FilterRegistrationBean . The former should be used on a class that is a Filter and in

Spring SimpleMappingExceptionResolver not going to default view

廉价感情. 提交于 2020-01-03 21:48:11
问题 I am playing with the SimpleMappingExceptionResolver to see how it works and to see if it will be of use to us for a client but I am having problems understanding it. What I have tried is visiting a particular page in my application and having it throw an exception in the handleRequestInternal method. When I throw a RecoverableDataAccessException (subclass of DataAccessException) then the correct error page is displayed as expected. When I throw a freemarker.core.InvalidReferenceException or

Get jsp output in spring controller as String

我与影子孤独终老i 提交于 2020-01-03 21:08:25
问题 Isn't there any easy way in Spring 4 by which we can achieve same as following code request.getRequestDispatcher("/WEB-INF/jsp/account_summary.jsp").include(request, response); To get output of a JSP file as a String in our controller. Presently I am using following code for this purpose HttpServletResponseWrapper responseWrapper = new HttpServletResponseWrapper(response) { private final StringWriter sw = new StringWriter(); @Override public PrintWriter getWriter() throws IOException { return