spring-mvc

Spring-MVC : Creating a good infrastructure(configuration) and avoiding duplicates

主宰稳场 提交于 2020-01-10 04:40:08
问题 I am working on a Spring-MVC application since some time. Recently I ran into some problems with @Scheduled methods, and I noticed that the whole configuration is getting loaded 4 times. Because of that the @Scheduled methods are getting called 4 times. The 3 configurations which are not correct, die out with NullPointerException(is what I was told on SO), and the one survives. I am very much interested to know how can I configure my project properly, so there is only one configuration which

Spring behind the scenes logging

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-10 03:18:30
问题 I use log4j2 and I can't get logging from spring. when I write my own logger.debug(...); it works but it's the same as System.out.println(...); . I want to know what happened behind the scenes in spring. show the created bean or debuggig error like 400 ... I try this Conf but nothing happened : <?xml version="1.0" encoding="UTF-8"?> <Configuration status="INFO"> <Appenders> <Console name="CONSOLE" target="SYSTEM_OUT"> <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n

Upgrading to spring-3.1 seems to break my CustomWebArgumentResolver

↘锁芯ラ 提交于 2020-01-10 02:18:08
问题 I'm trying to upgrade a spring MVC app from 3.0.6 to 3.1.2 and some controllers that used to work don't seem to work anymore. I've read the spring docs, but I'm confused about what's compatible with what. We've got a CustomWebArgumentResolver that looks for any request parameter named "asOf" and coverts its value to a date. We call it, unimaginatively, the "AsOfDateConverter." When upgrading to spring-3.1.2, I took advantage of the new namespace functionality and added this to my

Spring synchronized method NOT SYNCHRONIZED

北城余情 提交于 2020-01-10 02:13:27
问题 Environment: apache tomcat 7 java 7 oracle 11g eclipse apache jmeter 2.1 spring hibernate I am working on a web application that receives requests from clients and generate sequence number for them according to the request type to be used in further processing. For generating a unique sequence number I have a method to get current sequence number from DB and increment it by 1 then update that record by new sequence number. The function: @Transactional public synchronized Long

Spring MVC, forward

情到浓时终转凉″ 提交于 2020-01-10 00:51:09
问题 Is there any difference between public class Controller1 extends AbstractController { @Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { return new AnotherController().handleRequest(request, response); } } and @Controller public class Controller1 { @RequestMapping ... public String handleRequest() { return "forward:/path_to_my_another_controller"; } } 回答1: They're similar, but not quite the same. The second

How to login a user with spring 3.2 new mvc testing

和自甴很熟 提交于 2020-01-09 19:46:46
问题 This works fine until I have to test a service that needs a logged in user, how do I add user to context : @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:applicationContext-test.xml") @WebAppConfiguration public class FooTest { @Autowired private WebApplicationContext webApplicationContext; private MockMvc mockMvc; @Resource(name = "aService") private AService aService; //uses logged in user @Before public void setup() { this.mockMvc = webAppContextSetup(this

How to set response header in spring mvc

六眼飞鱼酱① 提交于 2020-01-09 13:08:29
问题 I have a method in which i want to set response header cache-control and pragma :- public String addUser(@Valid User user, BindingResult bindingResult) { if(bindingResult.hasErrors()) { bindingResult.getFieldError(); return"edit"; } return "redirect:/welcome/profile/"+user.getName(); } In this method i want to set cache-control and pragma like we do in simple servlet code using HttpservletResponse calling setHeader method :- response.setHeader("Cache-Control","no-cache,no-store,must

How to set response header in spring mvc

家住魔仙堡 提交于 2020-01-09 13:08:12
问题 I have a method in which i want to set response header cache-control and pragma :- public String addUser(@Valid User user, BindingResult bindingResult) { if(bindingResult.hasErrors()) { bindingResult.getFieldError(); return"edit"; } return "redirect:/welcome/profile/"+user.getName(); } In this method i want to set cache-control and pragma like we do in simple servlet code using HttpservletResponse calling setHeader method :- response.setHeader("Cache-Control","no-cache,no-store,must

Spring mvc 3.1 integration tests with session support

ぃ、小莉子 提交于 2020-01-09 12:45:44
问题 I'm using the new spring-test in the 3.1 version to run integration tests. It works really well but I can't make the session to work. My code: @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration("src/main/webapp") @ContextConfiguration({"classpath:applicationContext-dataSource.xml", "classpath:applicationContext.xml", "classpath:applicationContext-security-roles.xml", "classpath:applicationContext-security-web.xml", "classpath:applicationContext-web.xml"}) public class SpringTestBase

Spring3 @ExceptionHandler for ServletRequestBindingException

若如初见. 提交于 2020-01-09 11:16:15
问题 I am using a Default AnnotationMethodHandlerAdapter which I believe should enable support for @ExceptionHandler. Unluckily, a ServletRequestBindingException is thrown if a call to a handler method like this below is coming in - and not Exception handler is invoked. @RequestMapping(value = "/v1/products/{code}", method = RequestMethod.GET, headers = "Accept=application/xml,application/json") @ResponseBody public ProductDemoDTO getProductByCode(@PathVariable final String code, @RequestParam