You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

部署Liferay7.3 GA1的Spring MVC Portlet Maven模块遇NPE报错求助

Troubleshooting Catastrophic Initialization Failure for Spring MVC Portlet in Liferay 7.3 GA1

Based on the stack trace you shared (showing a NullPointerException in WabBundleProcessor.initContext), this issue typically comes down to misconfiguration, missing dependencies, or classloading conflicts when deploying your Spring MVC portlet. Let’s walk through the most likely fixes:

1. Validate Core Portlet Configuration Files

First, double-check your portlet setup files for errors:

  • portlet.xml: Ensure the portlet class points to Spring’s dispatcher and the context path is correctly defined:
    <portlet>
        <portlet-name>YourPortletName</portlet-name>
        <portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class>
        <init-param>
            <name>contextConfigLocation</name>
            <value>/WEB-INF/spring-portlet.xml</value>
        </init-param>
        <!-- Add other required portlet settings here -->
    </portlet>
    
  • liferay-portlet.xml: Confirm the portlet-name matches the entry in portlet.xml, and there are no invalid Liferay-specific properties.

2. Align Maven Dependencies with Liferay 7.3’s Spring Version

Liferay 7.3 uses Spring 5.x, so your dependencies must avoid version conflicts:

  • Include the required Spring portlet dependency (adjust the version to match Liferay’s bundled Spring version if needed):
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc-portlet</artifactId>
        <version>5.2.3.RELEASE</version>
        <scope>provided</scope> <!-- Use 'compile' if Liferay doesn't provide this -->
    </dependency>
    
  • Run mvn dependency:tree to identify duplicate or conflicting Spring jars that could break classloading.

3. Ensure Proper OSGi Metadata for the WAR

Liferay 7.x requires WARs to have valid OSGi headers. Use the Liferay Maven plugin to generate this automatically:

<plugin>
    <groupId>com.liferay</groupId>
    <artifactId>com.liferay.maven.plugin</artifactId>
    <version>7.3.0</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>build</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <pluginType>portlet</pluginType>
        <liferayVersion>7.3.0</liferayVersion>
        <!-- Add your Liferay server path configurations here -->
    </configuration>
</plugin>

This ensures the WAR is recognized as an OSGi bundle with the correct Web-ContextPath and package imports/exports.

4. Verify Spring Context File is Present and Valid

  • Confirm your Spring context file (e.g., spring-portlet.xml) exists in the /WEB-INF/ directory of your deployed WAR.
  • Check for XML syntax errors or missing bean definitions in the context file—invalid XML can cause silent failures that lead to the NPE.

5. Debug Classloading Issues

The NPE might signal a missing class the WAB processor expects:

  • Use Liferay’s Gogo shell to check if required packages are available. Run this command:
    packages org.springframework.web.portlet
    
  • If the package isn’t exported, ensure the Spring bundle is deployed in Liferay (it should be included by default, but a corrupted installation might cause it to be missing).

Extra Debugging Step

Enable debug logging for the WAB extender to get more detailed error context:
Add this line to Liferay’s portal-log4j.xml:

<logger name="com.liferay.portal.osgi.web.wab.extender">
    <level value="debug" />
</logger>

This will log additional details about what’s failing during initialization.


Your Deployment Stack Trace:

2020-02-28 14:41:14.570 ERROR [fileinstall-/usr/share/portail/liferay-ce-portal-7.3.0-ga1/osgi/war][WabBundleProcessor:244] Catastrophic initialization failure! Shutting down null WAB due to: null java.lang.NullPointerException at com.liferay.portal.osgi.web.wab.extender.internal.WabBundleProcessor.initContext(WabBundleProcessor.java:463) at com.liferay.portal.osgi.web.wab.extender.internal.WabBundleProcessor.init(WabBundleProcessor.java:140) at com.liferay.portal.osgi.web.wab.extender.internal.WebBundleDeployer._initWabBundle(WebBundleDeployer.java:159) at com.liferay.portal.osgi.web.wab.extender.internal.WebBundleDeployer.doStart(WebBundleDeployer.java:88) at com.liferay.portal.osgi.web.wab.extender.internal.WabFactory$WABExtension.start(WabFactory.java:113)
2020-02-28 14:41:14.572 ERROR [Framework Event Dispatcher: Equinox Container: 4c0cd32f-6426-4a62-bb58-24614ae72cc6][Framework:93] FrameworkEvent ERROR org.osgi.framework.ServiceException: Exception in com.liferay.portal.osgi.web.servlet.context.helper.internal.ServletContextHelperRegistrationServiceFactory.getService() at org.eclipse.osgi.internal.serviceregistry.ServiceFactoryUse.factoryGetService(ServiceFactoryUse.java:222) at org.eclipse.osgi.internal.serviceregistry.ServiceFactoryUse.getService(ServiceFactoryUse.java:111)... Caused by: java.lang.ExceptionInInitializerError at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

内容的提问来源于stack exchange,提问作者m.irouch

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 18:32:36