spring-3

customizing spring 3 mvc:annotation for RequestMappingHandlerMapping

社会主义新天地 提交于 2019-12-05 04:06:32
I am using <mvc:annotation-driven/> and I would like to configure RequestMappingHandlerMapping for disabling useTrailingSlashMatch . When I declare another RequestMappingHandlerMapping, I will end up 2 RequestMappingHandlerMapping . How can I configure RequestMappingHandlerMapping ? As you have already noted, this is feasible in xml by removing mvc:annotation-driven and replacing with the entire xml equivalent: <bean name="handlerAdapter" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"> <property name="webBindingInitializer"> <bean class="org

Elegant way to get Locale in Spring Controller [duplicate]

只谈情不闲聊 提交于 2019-12-05 01:30:38
This question already has an answer here: Finding Locale from Controller in Spring MVC 1 answer I'm looking for a cleaner way (in Spring 3.2) to get the current locale than explicitly calling LocaleContextHolder.getLocale() at the start of each Controller method. It has to be compatible with Java annotation, as I'm not using the XML config. Here's what I'm doing currently. @Controller public class WifeController { @Autowired private MessageSource msgSrc; @RequestMapping(value = "/wife/mood") public String readWife(Model model, @RequestParam("whatImDoing") String iAm) { Locale loc =

How to perform logout programmatically in spring 3

老子叫甜甜 提交于 2019-12-05 00:12:26
I have a spring configuration for logout like follows: <logout logout-url="/abc/logout" logout-success-url="/abc/login"/> Now I want to do programmatically logout. How I can achieve this in Spring 3. I need to do logout from one of my controller which has the following def. and currently I am doing something like following...Is this a good idea.. public void suppressUserProfile() { //... return "redirect:/abc/logout"; } Dirk Lachowski It depends. If it's ok for your app to place the logged out user on the "you have been logged out" page then this may be ok. But you can't be sure if your user

java.lang.NoSuchMethodError: org.springframework.beans.factory.xml.XmlReaderContext.getResourceLoader()Lorg/springframework/core/io/ResourceLoader

扶醉桌前 提交于 2019-12-04 19:48:54
问题 I am working on a Spring application on Tomcat7, JDK1.7, Maven and other components. Recently, I made a major change to the application, requiring switching over to Spring 3. After the change, I'm seeing the below exception on deploying to dev server. The application runs flawlessly on my local system though. javax.servlet.ServletException: Servlet.init() for servlet amadeusAce threw exception org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) org.apache

Spring:Propagation.REQUIRED not working

戏子无情 提交于 2019-12-04 19:20:25
I am inserting records in a couple of tables namely Dept and Emp . If the Dept table is successfully created then only I want to insert records in Emp table. Also, if any of the insert in Emp fails, then I want to rollback all the transaction which includes both rollback from Emp as well as Dept tables. I tried this using Propagation.REQUIRED as shown below: Java File public void saveEmployee(Employee empl){ try { jdbcTemplate.update("INSERT INTO EMP VALUES(?,?,?,?,?)",empl.getEmpId(),empl.getEmpName(), empl.getDeptId(),empl.getAge(),empl.getSex()); } catch (DataAccessException e) { e

Spring 3 Security j_spring_security_check

我的未来我决定 提交于 2019-12-04 17:18:56
问题 I'm trying to learn, how spring security works, so I've downloaded some sample project and then I tried to implement that solution to my project. But when I try to login, I get 404 error and in an address bar I have http://localhost:8080/fit/j_spring_security_check . I tried to look at similar questions here, but I wasn't able to realize, how to apply it to my project. I'd be really thankful, if somebody, who is more experienced, could help me. My app structure looks like this:

Spring MVC 3 : Ambiguous mapping found

筅森魡賤 提交于 2019-12-04 16:29:39
问题 I am playing with spring MVC 3.1 and testing different features. I wanted to verify following statement taken from @RequestMapping#value doc If you have a single default method (without explicit path mapping), then all requests without a more specific mapped method found will be dispatched to it. If you have multiple such default methods, then the method name will be taken into account for choosing between them So I created following controller with multiple default handler methods.

Spring 3 Security: AccessDeniedHandler is not being invoked

若如初见. 提交于 2019-12-04 16:22:45
问题 I have a spring 3 application with the configurations given below. When any user tries to access a page and he/she isn't logged in, I get an Access is Denied exception with an ugly stack trace. How do I handle this exception and not let it dump out a stack trace. I implemented my own access-denied-handler but that doesn't get invoked. Based on the type of the requested resource, I would like to show custom error messages or pages. Here is my spring configuration. How do I get Spring to invoke

How to use @RequestBody with a JSONP request?

左心房为你撑大大i 提交于 2019-12-04 15:37:30
I am trying to perform an ajax request using the jsonp data type due to cross domain issues in a clustered environment. I can make jsonp requests to methods mapped with no @RequestBody parameters, but when I do try to implement a RequestMapping with a @RequestBody parameter I get a 415 Unsupported Media Type error. Usually when I get this problem it is due to some property not mapping correctly between the json object posted and the Java object it is mapped to in Spring. But the only discrepency I can find is that using jsonp it adds a parm named callback and one with the name of an underscore

How to test POST spring mvc

我的未来我决定 提交于 2019-12-04 13:53:15
问题 My problem is to how to call this. I could do MyObject o = new MyObject(); myController.save(o, "value"); but this is not what I would like to do. I would like the MyObject to be in the request post body? How can this be done? @Requestmapping(value="/save/{value}", method=RequestMethod.POST) public void post(@Valid MyObject o, @PathVariable String value{ objectService.save(o); } Just to be clear I am talking about unit testing. Edit: @RequestMapping(value = "/", method = RequestMethod.POST)