Foren

prepopulate users through a webapp in liferay 7

thumbnail
Luca Stancapiano, geändert vor 7 Jahren.

prepopulate users through a webapp in liferay 7

New Member Beiträge: 9 Beitrittsdatum: 09.10.15 Neueste Beiträge
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, geändert vor 7 Jahren.

RE: prepopulate users through a webapp in liferay 7

Liferay Legend Beiträge: 14914 Beitrittsdatum: 02.09.06 Neueste Beiträge
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.