留言板

prepopulate users through a webapp in liferay 7

thumbnail
Luca Stancapiano,修改在7 年前。

prepopulate users through a webapp in liferay 7

New Member 帖子: 9 加入日期: 15-10-9 最近的帖子
I have a simple webapp deployed inside the wildfly iferay-ce-portal-7.0-ga2 bundle.

This webapp is deployed inside wildfly (not with the liferay deployer) and starts a singleton that would prepopulate liferay users. Here a sample:

package test;
import static com.liferay.portal.service.UserLocalServiceUtil.getUserByUuidAndCompanyId;

import java.io.Serializable;

import javax.annotation.PostConstruct;
import javax.ejb.EJBContext;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.inject.Named;

import com.liferay.portal.kernel.exception.PortalException;

@Named("userModule")
@Startup
@Singleton
public class LiferayUserModule implements Serializable {

	@PostConstruct
	public void init() {
		try {
			getUserByUuidAndCompanyId("test", 0);
		} catch (PortalException e) {
			e.printStackTrace();
		}
	}
}


at the start of wildfly I get this error using the UserLocalServiceUtil api:

Caused by: com.liferay.portal.kernel.bean.BeanLocatorException: BeanLocator has not been set
	at com.liferay.portal.kernel.bean.PortalBeanLocatorUtil.locate(PortalBeanLocatorUtil.java:82)
	at com.liferay.portal.service.UserLocalServiceUtil.getService(UserLocalServiceUtil.java:3182)
	at com.liferay.portal.service.UserLocalServiceUtil.getUserByUuidAndCompanyId(UserLocalServiceUtil.java:1780)


It happened beacuse the BeanLocator of Liferay is not initialized. What misses in the war? Here the complete webapp sample: https://github.com/flashboss/prepopulate-liferay-users
thumbnail
David H Nebinger,修改在7 年前。

RE: prepopulate users through a webapp in liferay 7

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
So services are not actually available until the ROOT web application has finished loading. Your naked web application is free to start after ROOT has started but is likely invoking this method long before ROOT has finished initializing.