使用Autowired在Liferay中安排任务 [英] Scheduled Tasks in Liferay with Autowired

查看:92
本文介绍了使用Autowired在Liferay中安排任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

im试图在liferay portlet中创建计划的任务.

im trying to create scheduled task in liferay portlet.

Liferay:6.2

Liferay: 6.2

春季:3.1.4.发布

Spring: 3.1.4.RELEASE

使用

    <scheduler-entry>
        <scheduler-description>test-scheduler</scheduler-description>
        <scheduler-event-listener-class>
            project.ScheduledProcesser
        </scheduler-event-listener-class>
        <trigger>

            <simple>
                <simple-trigger-value>
                    1
                </simple-trigger-value>
                <time-unit>minute</time-unit>
            </simple>

        </trigger>
    </scheduler-entry>

和对应的类

@Component
public class ScheduledProcesser implements MessageListener {
private static Log log = LogFactoryUtil
            .getLog(ScheduledProcesser.class);


    @Autowired
    @Qualifier("myRequestService")
    private RequestService service;

    @Override
    public void receive(Message message) throws MessageListenerException {

        log.info("Starting");

        Request req = service.get("AAA746");

        if (req!=null)
        log.info("REQ -" + req.getId());

        log.info("Finished");
    }

该方法正在触发.但是服务组件为空.通常其他部分的服务运行良好.

The method is firing. But the service component is null. Normally is the service in other parts working well.

我试图找到解决方案,但也许缺少某些设置. 谢谢,

I have tried to find the solution, but maybe there is some settings missing. Thanx,

推荐答案

MessageListener不是由Spring实例化的,而是由Liferay实例化的(请参见QuartzSchedulerEngine.getMessageListener(String, ClassLoader)的实现).而Liferay只是实例化该类.因此,您无法将任何内容自动连接到liferay-portlet.xml中定义的MessageListener中.

MessageListener is not instantiated by Spring, but by Liferay (see the implementation of QuartzSchedulerEngine.getMessageListener(String, ClassLoader)). And Liferay just instantiates the class. So you can't autowire anything into a MessageListener that is defined in the liferay-portlet.xml.

但是,如果您的服务是在门户网站应用程序上下文中定义的,则可以改用PortalBeanLocatorUtil.locate.

But you could use PortalBeanLocatorUtil.locate instead, if your service is defined in the portal application context.

这篇关于使用Autowired在Liferay中安排任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆