spring-mvc

Access session scoped variable in spring interceptor

北城以北 提交于 2020-01-04 18:14:12
问题 How can i access session scoped variable in spring interceptor? Session scoped class: @Component @Scope("session") public class User { } Controller: @Controller @RequestMapping("/restricted") @Scope("request") public class RestrictedController { @Autowired private User user; } Dispatcher servlet: <mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/restricted/*"/> <bean class="com.interceptors.RestrictedInterceptor" /> </mvc:interceptor> </mvc:interceptors> Interceptor class: public class

Spring mvc: css does not work when adding slash at the end of URL

大兔子大兔子 提交于 2020-01-04 15:27:44
问题 I am new to Spring MVC and i am having a problem with CSS. When the URL ends with slash CSS does not work. link goes like this <link rel="stylesheet" href="themes/style.css"> mvc:resources mapping <mvc:resources mapping="/themes/**" location="/WEB-INF/themes/"/> and requestMapping goes like this @RequestMapping("/login") public ModelAndView loginPage() { ModelAndView model = new ModelAndView("login"); return model; } So the problem is when i enter a URL like ../login the css loads normally,

Spring 4 Exception Handling : No suitable resolver for argument

北城余情 提交于 2020-01-04 15:15:11
问题 Problem Statement Migration to Spring 4 from Spring 3 induces some exceptions in exception handling flow. The Exception says No suitable resolver for argument in the org.springframework.web.method.support.InvocableHandlerMethod class. So whenever and exception occurs Spring tries to find the Exception Handler which it gets but when it tries to populate the method arguments or exception Handler it throws the below exception Failed to invoke @ExceptionHandler method: public org.springframework

HttpMediaTypeNotSupportedException when trying to test handling of HTTP POST

余生颓废 提交于 2020-01-04 15:15:05
问题 I am trying to test POST method in spring framework but I keep getting errors all the time. I first tried this test: this.mockMvc.perform(post("/rest/tests"). param("id", "10"). param("width","25") ) .andDo(MockMvcResultHandlers.print()) .andExpect(status().isOk()); and got the following error: org.springframework.http.converter.HttpMessageNotReadableException Then I tried to modify the test as below: this.mockMvc.perform(post("/rest/tests/"). content("{\"id\":10,\"width\":1000}")) .andDo

Product creation doesn't work (under Spring MVC with JPA)

こ雲淡風輕ζ 提交于 2020-01-04 11:55:28
问题 Well, the code is working under the Test Enviroment, but not on the front context of the application. This is driving me crazy to be honest. Here is the controller : package org.admios.nuevoproyecto.controller; import java.util.List; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.annotation.InitBinder; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.validation.BindingResult; import org.admios.nuevoproyecto.dao

Adding system properties in Spring MVC webapp

本小妞迷上赌 提交于 2020-01-04 09:37:05
问题 I am using Hibernate 4.3.7.Final and Log4j2 in my Spring MVC webapp, published via Tomcat 7. All configuration is done via JavaConfig (i.e. there is no web.xml or other XML config files). By default the Hibernate logging does not go through Log4j, for reasons explained in the Apache wiki. In order to resolve this I need to create a system setting as follows: System.setProperty("org.jboss.logging.provider", "slf4j"); As my application is a webapp there is no Main thread, and as a result I an

Adding system properties in Spring MVC webapp

拥有回忆 提交于 2020-01-04 09:31:19
问题 I am using Hibernate 4.3.7.Final and Log4j2 in my Spring MVC webapp, published via Tomcat 7. All configuration is done via JavaConfig (i.e. there is no web.xml or other XML config files). By default the Hibernate logging does not go through Log4j, for reasons explained in the Apache wiki. In order to resolve this I need to create a system setting as follows: System.setProperty("org.jboss.logging.provider", "slf4j"); As my application is a webapp there is no Main thread, and as a result I an

When should a Spring MVC controller method have @ResponseBody?

一笑奈何 提交于 2020-01-04 09:05:30
问题 I use the @ResponseBody annotation with my Spring controller but I'm not sure when to use it. Also, I named my method index and I wonder if that matters. My method head is @RequestMapping(value = "/addproduct", method = RequestMethod.POST) public ModelAndView index(@RequestParam("name") String name, @RequestParam("file") MultipartFile file, @RequestParam("desc") String desc,) { But in another method in the same controller I use the @ResponseBody and I want to know when that usage is correct:

Spring Security Unit Test With Csrf causes HttpServletResponse to not be found

只愿长相守 提交于 2020-01-04 06:30:42
问题 I was unable to find this question asked anywhere else. I have my unit test setup as follows: @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = Application.class) //@DatabaseSetup("classpath:decks.xml") @WebIntegrationTest public class DeckControllerTest { @Autowired private WebApplicationContext context; private MockMvc mockMvc; @Before public void setup() { mockMvc = MockMvcBuilders .webAppContextSetup(context) .apply(springSecurity()) .build(); } @Test

Spring Boot Undertow add both blocking handler and NIO handler in the same application

荒凉一梦 提交于 2020-01-04 06:04:04
问题 In my previous question (thank @Andy Wilkinson) I figured out that all incoming requests to an undertowEmbeddedServletContainer are handled by a worker thread (blocking operation). According to Andy, I try to add a UndertowBuilderCustomizer in order to override the ServletInitializerHandler to handle incoming requests with a non-blocking handler. @Bean public UndertowEmbeddedServletContainerFactory undertowEmbeddedServletContainerFactory(){ UndertowEmbeddedServletContainerFactory