I have created a liferay portlet application using Spring, thymeleaf and AngularJS. For communication between AngularJS
and spring I need to create some rest calls which I have created using @ResourceMapping
like as shown below. The application is working fine but the problem is that I don't know how to make GET
, DELETE
, PUT
http REST
calls since @ResourceMapping
is not allowing to specify any methods.
@ResourceMapping(value="getUserDetail")
public void userDetail(@RequestParam long userId, ResourceResponse response) throws Exception {
Users users = new Users(userId);
// some logic
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
JSON_MAPPER.writeValue(response.getPortletOutputStream(), users);
}
When I used @RequestMapping
instead of @ResourceMapping
like as shown below
@RequestMapping(value="getUserDetail", method=RequestMethod.GET)
@ResponseBody
public void userDetail(@RequestParam long userId, ResourceResponse response) throws Exception {
System.out.println("Got detail request for user with id {} "+ userId);
// UserDetail userDetail = this.userService.getPortalUserDetail(userId);
List<String> users = new ArrayList<String>();
users.add("Manu");
users.add("Lissie");
users.add("John");
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
JSON_MAPPER.writeValue(response.getPortletOutputStream(), users);
}
I have got
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.portlet.mvc.annotation.DefaultAnnotationHandlerMapping': Initialization of bean failed; nested exception is java.lang.IllegalStateException: Mode mappings conflict between method and type level: [getUserDetail] versus [view]
Can anyone please tell me some solution for this
- How to create different types of http calls using
@ResourceMapping
- Can we use
@RequestMapping
instead of@ResourceMapping
in Liferay Spring portlet forREST
calls - How can we create resource based
REST
urls likegetUser/12/mumbai
- How can we send
REST
json as body instead of Request Param