使用服务构建器(Liferay)时,尚未为servlet上下文My_portlet设置BeanLocator

时间:2015-10-14 16:07:59

标签: liferay spring-portlet-mvc

使用MVC spring Liferay 6.2 portlet。 我已经构建了一个服务xml文件并构建了该项目。它管理一个实体(比方说MyEntity)。 当我从我的控制器调用addMyEntity(long id)方法时,抛出异常说: 15:53:04,135 ERROR [http-bio-8080-exec-60] [PortletBeanLocatorUtil:42]对于servlet上下文My_portlet,BeanLocator为null com.liferay.portal.kernel.bean.BeanLocatorException:尚未为servlet上下文设置BeanLocator My_portlet

它看起来门户网站无法访问某些bean资源。 我的web.xml文件包含以下内容:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring-context/portlet-application-context.xml</param-value>
</context-param>
<servlet>
    <servlet-name>ViewRendererServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.ViewRendererServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>ViewRendererServlet</servlet-name>
    <url-pattern>/WEB-INF/servlet/view</url-pattern>
</servlet-mapping>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

portlet-application-context.xml仅包含以下bean:

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="contentType" value="text/html;charset=UTF-8" />
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
    </bean>

我认为服务器正在寻找的是存储在portlet-spring.xml文件中的这些bean:

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" default-destroy-method="destroy" default-init-method="afterPropertiesSet" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
    <bean id="com.company.project.servicebuilder.dao.service.MyEntityLocalService" class="com.company.project.servicebuilder.dao.service.impl.MyEntityLocalServiceImpl" />
    <bean id="com.company.project.servicebuilder.dao.service.MyEntityService" class="com.company.project.servicebuilder.dao.service.impl.MyEntityServiceImpl" />
    <bean id="com.company.project.servicebuilder.dao.service.persistence.MyEntityPersistence" class="com.company.project.servicebuilder.dao.service.persistence.MyEntityPersistenceImpl" parent="basePersistence" />
</beans>

但是,我在其他文件中看不到对portlet-spring.xml的引用,所以我担心在部署portlet时永远不会声明这些bean。 它应该在某处引用吗?

除了我的假设之外的任何其他建议吗?

提前thx。

3 个答案:

答案 0 :(得分:1)

感谢用户“So Te”以及一些广泛的研究,我解决了这个问题,在配置标记的pom.xml中指定pluginName并再次运行service-builder。

<configuration>
  <autoDeployDir>${liferay.auto.deploy.dir}</autoDeployDir>
  <appServerDeployDir>${liferay.app.server.deploy.dir}</appServerDeployDir>
  <appServerLibGlobalDir>${liferay.app.server.lib.global.dir}</appServerLibGlobalDir>
  <appServerPortalDir>${liferay.app.server.portal.dir}</appServerPortalDir>
  <liferayVersion>${liferay.version}</liferayVersion>
  <pluginType>portlet</pluginType>
  <pluginName>${project.artifactId}-${project.version}</pluginName>
</configuration>

答案 1 :(得分:0)

尝试删除portlet并再次部署它,正常情况下这个问题是部署错误。

答案 2 :(得分:0)

构建我的JUnit测试用例时出现此错误。我遇到此错误是因为Mockito独立版不支持静态调用。为了解决这个问题,我必须使用Mockito with PowerMock才能进行静态调用。