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
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]
– Oleic@RequestMapping
– Oleic@Controller
and have created a@RequestMapping
function like as above, now I am getting 404 – Oleic@RequestMapping
value that you use now. The@RequestMapping
must have placed the endpoint in a different URL. For example if before you usedlocalhost:12345/api/getSomething
, maybe now the endpoint is underlocalhost:12345/getSomething
or the opposite. – Shrubbyhttp://localhost:8082/web/guest/welcome?p_p_id=fileprocessorportlet_WAR_fil%E2%80%A6e=view&p_p_cacheability=cacheLevelPage&p_p_col_id=column-1&p_p_col_count=3&p_p_resource_id=userDetail&userId=1
. Now I have My controller class as SampleRESTFullController.java and I have tries to call it ashttp://localhost:8082/file-processor-portlet/services/auth/user
but got 404 – Oleichttp://localhost:8082/auth/user
orhttp://localhost:8082/file-processor-portlet/auth/user
orhttp://localhost:8082/services/auth/user
. I don't know how you have configured your app. – Shrubby