spring-mvc

Setting model attributes for every action within each controller

余生颓废 提交于 2020-01-17 09:11:27
问题 I would like to set three common attributes on my model for each @RequestMapping within the many controllers in a Spring Boot application. I have read about @ModelAttribute but it needs to be placed within each Controller. I have more than 20 controllers in my application and each having more than 10 @RequestMapping . Is there a way to set such model attributes in one place which gets initialized at the start of the application? 回答1: If you want to execute some code on Spring Boot startup,

How do make Spring access dropdown box values

时光毁灭记忆、已成空白 提交于 2020-01-17 09:01:44
问题 How do make Spring access dropdown box values. I am trying to make Spring MVC get the value of one of my dropdowns. org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/view/dateRange.jsp at line 28 25: <tr> 26: <td> 27: <div align="right">Last Month Of Full Data:</div></td> 28: <td><form:select path="Lst_mnt"> 29: <option value="1">January</option> 30: <option value="2">February</option> 31: All that I am doing its to get the value into Spring not build the

Apache Tiles in Spring mvc project

点点圈 提交于 2020-01-17 08:16:31
问题 I am absolutely new to Tiles and novice in spring mvc. I want to add tiles view in my current configuration. Please help So far I have done this, but not working: @EnableWebMvc @Configuration @ComponentScan({"com.kharoud"}) public class MvcConfiguraion extends WebMvcConfigurerAdapter{ private PerformanceMonitorInterceptor performanceInteceptor; @Override public void configureDefaultServletHandling( DefaultServletHandlerConfigurer configurer ){ configurer.enable(); } @Override public void

Apache Tiles in Spring mvc project

倾然丶 夕夏残阳落幕 提交于 2020-01-17 08:16:04
问题 I am absolutely new to Tiles and novice in spring mvc. I want to add tiles view in my current configuration. Please help So far I have done this, but not working: @EnableWebMvc @Configuration @ComponentScan({"com.kharoud"}) public class MvcConfiguraion extends WebMvcConfigurerAdapter{ private PerformanceMonitorInterceptor performanceInteceptor; @Override public void configureDefaultServletHandling( DefaultServletHandlerConfigurer configurer ){ configurer.enable(); } @Override public void

Unable to load freemarker template using multipartResolver

北战南征 提交于 2020-01-17 08:01:02
问题 I am using MultipartFile configured in my Spring MVC app via the classpath: <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="maxUploadSize" value="1000000"/> </bean> <bean id="MyController" class="myController"> <property name="myTemplate" value="classpath:myTemplate.txt"/> </bean> And I am trying to use freemarker in order to load this templete: public class MyController { private Resource myTemplate; .... Configuration

Various Spring MVC RequestMapping configuration questions

南笙酒味 提交于 2020-01-17 04:20:26
问题 I have several (albeit related) questions about Spring MVC RequestMapping configuration: Say I have a type-level RequestMapping annotation as follows: @RequestMapping("/root/") . What is the difference between adding this method-level RequestMapping: @RequestMapping(value="leaf") and that one: @RequestMapping(value="/leaf") ? Notice the leading slash in second method-level mapping. What is the difference between having this type-level RequestMapping: @RequestMapping("/root/") and that one

EclipseLink - Error: Attempted to redeploy a session without closing it

早过忘川 提交于 2020-01-17 04:13:34
问题 I have a application running in AWS BeanStalk (Tomcat8 + SpringMVC + PostgreSQL + EclipseLink). The application is running ok but after some time running (2 hours) one error starting to happen: The intercepted error is: org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: Exception [EclipseLink-28013] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse

Spring 3.0 RESTful Controller Fails on Redirect

早过忘川 提交于 2020-01-17 03:46:07
问题 I am setting up a simple RESTful controller for a Todo resource with an XML representation. It all works great - until I try to redirect. For example, when I POST a new Todo and attempt to redirect to its new URL (for example /todos/5 , I get the following error: Error 500 Unable to locate object to be marshalled in model: {} I do know the POST worked because I can manually go to the new URL ( /todos/5 ) and see the newly created resource. Its only when trying to redirect that I get the

Get rid of first View Controller with Spring 4 and AngularJS

十年热恋 提交于 2020-01-17 03:38:25
问题 I use RestController to fetch data with AngularJS , but still I need regular controller to load index.html : @Controller public final class LayoutController { @RequestMapping(value = "/") public String getIndexPage() { return "/resources/index"; } } Every other controllers are RestController s. If index file has jsp extension, I don't neeed LayoutController , but when it is html it is needed. This is my dispatcher config: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www

403 response for POST/PUT/DELETE request in spring boot + spring security application

一个人想着一个人 提交于 2020-01-17 02:39:11
问题 I am using spring security in my spring boot rest app. Get requests are working fine but POST/PUT/DELETE request are giving "403 Forbidden". Below is my code snippet. UI is in Angular 6 @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true) public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired private UserService userService; @Override protected void configure(HttpSecurity http) throws Exception { CustomAuthorizationFilter