RE: Exception while accessing rest url via RestTemplate in Liferay MVC port

Anji E, modified 6 Years ago. Junior Member Posts: 49 Join Date: 11/18/14 Recent Posts
We are getting a weird issue while invoking rest API using spring RestTemplate() in MVC portlet ( Liferay 6.2)



In our project, we have developed few module in spring mvc portlet and few module in Liferay Mvc portlet.
We have written a common service jar which has code to invoke rest services using spring RestTemplate.

We have created 2 pages and added Liferay mvc in page-1 and spring mvc in page-2

Problem:

1. If we access the Page-1 (Liferay mvc portlet ) we are getting below run time exception .

           java.lang.NoSuchMethodError:               com.fasterxml.jackson.databind.SerializationConfig.withDefaultPrettyPrinter(Lcom/fasterxml/jackson/core/PrettyPrinter;)
                   Lcom/fasterxml/jackson/databind/SerializationConfig;
                  at com.fasterxml.jackson.dataformat.xml.XmlMapper.<init>(XmlMapper.java:86)
                  at com.fasterxml.jackson.dataformat.xml.XmlMapper.<init>(XmlMapper.java:67)
                 at com.fasterxml.jackson.dataformat.xml.XmlMapper.<init>(XmlMapper.java:63)

2. If we access the Page-2 (Spring mvc portlet) and then  page-1 (Liferay mvc portlet ) we are not getting any error.

we sucspecting that few spring related jars are not loading for the first time in Liferay mvc portet. 

Below are the dependencies we have added in both portlets . We have compared the jar files in both the war. All jar files are same.

We are not facing this problem in weblogic server not in Lifery tomcat server

<dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>4.3.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>4.3.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.8.3</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security.oauth</groupId>
            <artifactId>spring-security-oauth2</artifactId>
            <version>2.0.2.RELEASE</version>
        </dependency>
        <dependency>


Please let us know if we missing to add or load any dependencies..
Anji E, modified 6 Years ago. Junior Member Posts: 49 Join Date: 11/18/14 Recent Posts
We found the solution . Problem was, in pom.xml we have included "jackson" dependency before the spring related dependency hence it was dowloading many jackson like "jackson-module-jaxb-annotations-2.8.3.jar" , "jackson-core-2.8.3.jar" which causing the invocation of different methods ... 



<dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.8.3</version>
 </dependency>

To fix the issue we have removed above dependency in all the portlets and added at one common service project which is included in all the portlets.
While including this dependecy we included after all the spring dependencies.

Still we did not understand how it was working second time when we access the spring portlet first (Page-1 )and then mvc portlet(Page-2)