To continue developing a portlet to use Spring Framework version 5.0 onward, migrate it from Spring Portlet MVC to PortletMVC4Spring. Here are the steps:
-
In your
pom.xml
orbuild.gradle
descriptor, use the Spring Framework version 5.1.x artifacts by replacing dependencies on thespring-webmvc-portlet
artifact with thecom.liferay.portletmvc4spring.framework
artifact.Maven:
<dependency> <groupId>com.liferay.portletmvc4spring</groupId> <artifactId>com.liferay.portletmvc4spring.framework</artifactId> <version>5.1.0</version> </dependency> <dependency> <groupId>com.liferay.portletmvc4spring</groupId> <artifactId>com.liferay.portletmvc4spring.security</artifactId> <version>5.1.0</version> </dependency>
Gradle:
compile group: 'com.liferay.portletmvc4spring', name: 'com.liferay.portletmvc4spring.framework', version: '5.1.0' compile group: 'com.liferay.portletmvc4spring', name: 'com.liferay.portletmvc4spring.security', version: '5.1.0'
-
In your
WEB-INF/portlet.xml
descriptor, replace uses oforg.springframework.web.portlet.DispatcherPortlet
withcom.liferay.portletmvc4spring.DispatcherPortlet
. -
Replace uses of the Spring Portlet MVC
AnnotationMethodHandlerAdapter
class with the PortletMVC4SpringPortletRequestMappingHandlerAdapter
class.PortletRequestMappingHandlerAdapter
uses theHandlerMethod
infrastructure that Spring Web MVC 5.1.x is based on. -
If you specified
AnnotationMethodHandlerAdapter
as a<bean>
in a Spring configuration descriptor, replace its fully-qualified class nameorg.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter
withcom.liferay.portletmvc4spring.mvc.method.annotation.PortletRequestMappingHandlerAdapter
.Also address these bean property changes:
-
customModelAndViewResolver
(no longer available) -
customArgumentResolver
(no longer available) -
customArgumentResolvers
(specify a list ofHandlerMethodArgumentResolver
instead of a list ofWebArgumentResolver
)
-
-
If you’re using Apache Commons Fileupload, update your Spring configuration descriptor:
-
Replace this legacy bean:
<bean id="portletMultipartResolver" class="org.springframework.web.portlet.multipart.CommonsPortletMultipartResolver" />
With this new one from PortletMVC4Spring:
<bean id="portletMultipartResolver" class="com.liferay.portletmvc4spring.multipart.CommonsPortletMultipartResolver" />
-
Remove these dependencies from your
pom.xml
orbuild.gradle
descriptor:<dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> </dependency>
-
-
Throughout your project, replace all uses of the
org.springframework.web.portlet
package path withcom.liferay.portletmvc4spring
.
Congratulations! You migrated your project from Spring Portlet MVC to PortletMVC4Spring.