标签: liferay-hook

Liferay 6.2 + Spring @Autowired没有在钩子里工作

我在Liferay 6.2中使用Spring 4.0.6.Spring无法将自动装配的组件注入到钩子中,对象变为null.我也尝试过带有liferay的spring 3.1版.相同的代码适用于portlet,但不适用于挂钩.

ActivityEventPublisher.java中的私有ApplicationEventPublisher发布者为null.

web.xml中

<?xml version="1.0"?>

<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-         app_2_4.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/applicationContext.xml</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<listener>
<listener-class>com.liferay.portal.kernel.servlet.SecurePluginContextListener</listener-  class>
</listener>
<listener>
<listener-class>com.liferay.portal.kernel.servlet.PortletContextListener</listener-class>
</listener>

<servlet>
<servlet-name>ViewRendererServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.ViewRendererServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ViewRendererServlet</servlet-name>
<url-pattern>/WEB-INF/servlet/view</url-pattern>
</servlet-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)

ActivityEventPublisher.java

import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Component;

import connect.activity.solr.document.ActivityData;

@Component
public class ActivityEventPublisher implements ApplicationEventPublisherAware {

private ApplicationEventPublisher publisher;

@Override
public void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
this.publisher = publisher;
}

public ApplicationEventPublisher getPublisher() {
return publisher;
}

public void setPublisher(ApplicationEventPublisher publisher) {
this.publisher …
Run Code Online (Sandbox Code Playgroud)

spring liferay-6 liferay-hook

1
推荐指数
1
解决办法
1954
查看次数

标签 统计

liferay-6 ×1

liferay-hook ×1

spring ×1