Forums de discussion

BeanLocator has not been set for servlet context

Tim Taylor, modifié il y a 11 années.

BeanLocator has not been set for servlet context

New Member Publications: 18 Date d'inscription: 19/09/12 Publications récentes
Hi,

i have create an persistence-classes with the ServiceBuilder (Book Example from the docu), and after the creation i have an IPC1-portlet-service.jar in the Web App Liberies directory.
In my project i have configured two protlets, one use the the BookService.
I deploy my portlets in Eclipse Juno

When i call addBook i get an Exception

public String createBook() {
try {
final ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
PortletRequest request = (PortletRequest) context.getRequest();
String userId = request.getRemoteUser();
User user = UserUtil.findByPrimaryKey(Integer.parseInt(userId));
System.out.println("User is [" + user + "]");
BookLocalServiceUtil.addBook(user.getPrimaryKey(), "A new title");
} catch (Exception e) {
e.printStackTrace();
}
return "send";
}


BeanLocator has not been set for servlet context IPC1-portlet

environment: Liferay 6.1.1, Primefaces 3.3

Any idea's? The jar name comes from the project-directory?

Thx Tim
thumbnail
David H Nebinger, modifié il y a 11 années.

RE: BeanLocator has not been set for servlet context

Liferay Legend Publications: 14919 Date d'inscription: 02/09/06 Publications récentes
There are many solutions to this already listed on the forum. All you need to do is google for BeanLocator has not been set...
Tim Taylor, modifié il y a 11 années.

RE: BeanLocator has not been set for servlet context

New Member Publications: 18 Date d'inscription: 19/09/12 Publications récentes
I have new expertises. When i create a new project (Eclipse) with a new Portlet than it works.

Facts:
The directory-Name is like "BookServiceProject-portlet", also the Eclipse-Project-Name.
The portlet-Name is like "BookServiceProject" (portlet.xml)
The Service-Jar is named BookServiceProject-portlet-service.jar (The Project-Name!!!)

If i change the portlet-name, it still works.
But when i change the Project-Name for the Eclipse-Project then i get the Error message

BeanLocator has not been set for servlet context BookServiceProject-portlet.

Why is the servlet context "BookServiceProject-portlet"?

My portlet is named "BookServicePortlet" and my Eclipse-Project-Name is BookServiceProject, only the directory is named "BookServiceProject-portlet"
From where is the servlet context?
Where is the relationship between my BookService the servlet context and the portlet.

Thx and best regards

Tim Taylor
thumbnail
David H Nebinger, modifié il y a 11 années.

RE: BeanLocator has not been set for servlet context

Liferay Legend Publications: 14919 Date d'inscription: 02/09/06 Publications récentes
When you create a new project in the IDE, it does a lot of magical things for you behind the scenes.

One of those things is the population of values in the portlet.xml, liferay-portlet.xml, and also the web.xml file.

Changing a project name does not, in turn, make any changes to the rest of these files, but does affect the ant build scripts. The other files define the context information for a runtime portlet, but the project name affects the path the artifact will be deployed as.

In short, it is a bad idea to change project name unless you are aware of all of the cascading impacts. As a rule, I recommend to my developers that they create a new project and copy the necessary data from the old to the new (most cases this is source files that move, but care must be taken in the portlet.xml, liferay-portlet.xml, and web.xml files to not just blindly overwrite them from the old project).
thumbnail
Konstantin Chudinov, modifié il y a 11 années.

RE: BeanLocator has not been set for servlet context

Junior Member Publications: 43 Date d'inscription: 23/04/13 Publications récentes
Tim Taylor:
I have new expertises. When i create a new project (Eclipse) with a new Portlet than it works.

From where is the servlet context?
Where is the relationship between my BookService the servlet context and the portlet.
Thx and best regards
Tim Taylor


Delete OldProject.jar from lib folder of new project.
Delete OldProject.jar from LIFERAY_HOME/tomcat/webapps/WEB-INF/lib
also clean temp folder under tomcat folder.

Hope this help somebody.
Also you can try to find "OldProject" under liferay_home folder and delete everything you will see
Christian Berndt, modifié il y a 10 années.

RE: BeanLocator has not been set for servlet context

New Member Publications: 10 Date d'inscription: 23/02/12 Publications récentes
David H Nebinger:
... All you need to do is google for BeanLocator has not been set...


Hi David,

I tried your recommendation, but I haven't been able to solve the issue.

The error occurs in the following setup:

  • Liferay 6.2.0-RC5
  • liferay-faces-3.2.4-ga5-SNAPSHOT
  • Maven SDK


The implementation of my test application follows the example of Neil's and Kyle's primefaces3-users-portlet example. But when I try replace the User entity with my ServiceBuilder generated custom entity, I get the above error.

Any hints, what I might have missed?

Thanks, Christian
Wojciech Tutro, modifié il y a 10 années.

RE: BeanLocator has not been set for servlet context

New Member Publications: 22 Date d'inscription: 15/07/13 Publications récentes
Hi,

After changing project name You have to check/define deployment context name for this portlet. Have You tried that?

Best regards
Christian Berndt, modifié il y a 10 années.

RE: BeanLocator has not been set for servlet context

New Member Publications: 10 Date d'inscription: 23/02/12 Publications récentes
Hi Wojciech,

sorry, but I do not understand your suggestion. I started a new primefaces-project, wich deploys and runs without errors, as long as I use Liferay's LocalServices. The BeanLocator issue only occurs, if I try to use a custom class built with Servicebuilder.

Best, Christian
Wojciech Tutro, modifié il y a 10 années.

RE: BeanLocator has not been set for servlet context

New Member Publications: 22 Date d'inscription: 15/07/13 Publications récentes
Hi,

How did You build Your services? Are they separate project? And Primefaces is another project with his own war? Did You include jar services into You primefaces project?

Have You generate Your ServiceBuilder project using maven archetype? Did you change something in the war name?

Best regards
Christian Berndt, modifié il y a 10 années.

RE: BeanLocator has not been set for servlet context

New Member Publications: 10 Date d'inscription: 23/02/12 Publications récentes
Hi Wojciech,

the services are built with the 6.2.0 ServiceBuilder and MavenSDK.

The service classes are part of the same project (all included in the same war).

No - I did not change anything in the war name - the WAR is deployed via auto-deploy dir, the respective log message are:

INFO: Initializing Spring root WebApplicationContext
Loading file:/home/berndt/Applications/liferay-portal-6.2.0-ce-rc5/tomcat-7.0.40/temp/8-MyNewsletter-1.0.0.2/WEB-INF/classes/service.properties
Loading file:/home/berndt/Applications/liferay-portal-6.2.0-ce-rc5/tomcat-7.0.40/temp/8-MyNewsletter-1.0.0.2/WEB-INF/classes/service.properties
12:00:50,476 INFO [ContainerBackgroundProcessor[StandardEngine[Catalina]]][HookHotDeployListener:687] Registering hook for MyNewsletter-1.0.0.2
12:00:50,483 INFO [ContainerBackgroundProcessor[StandardEngine[Catalina]]][HookHotDeployListener:814] Hook for MyNewsletter-1.0.0.2 is available for use
12:00:50,490 INFO [ContainerBackgroundProcessor[StandardEngine[Catalina]]][PortletHotDeployListener:343] Registering portlets for MyNewsletter-1.0.0.2
12:00:50,791 INFO [BridgeImpl] Initializing Liferay Faces Bridge 3.2.3-ga4-SNAPSHOT (Ephesus / Sep 7, 2013 AD)
Loading file:/home/berndt/Applications/liferay-portal-6.2.0-ce-rc5/tomcat-7.0.40/temp/8-MyNewsletter-1.0.0.2/WEB-INF/classes/portlet.properties
12:00:51,105 INFO [ContainerBackgroundProcessor[StandardEngine[Catalina]]][PortletHotDeployListener:490] 1 portlet for MyNewsletter-1.0.0.2 is available for use
12:00:51,114 INFO [BridgeSessionListener:87] Context initialized for contextPath=[/MyNewsletter-1.0.0.2]
12:00:53,480 INFO [StartupListener:50] Context initialized for contextPath=[/MyNewsletter-1.0.0.2]
12:00:53,500 INFO [StartupListener:77] Copied input-editor.jsp from LiferayFaces JAR to context path file=[/home/berndt/Applications/liferay-portal-6.2.0-ce-rc5/tomcat-7.0.40/temp/8-MyNewsletter-1.0.0.2/resources/liferay-ui/jsp/input-editor.jsp]
Dec 2, 2013 12:00:53 PM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/MyNewsletter-1.0.0.2] is completed

Perhaps a listener missing?

Best, Christian
Wojciech Tutro, modifié il y a 10 années.

RE: BeanLocator has not been set for servlet context

New Member Publications: 22 Date d'inscription: 15/07/13 Publications récentes
Hi,

There is something that I am missing... When You generate archetype for Liferay service builder You should have 2 projects (that was in liferay 6.1 - maybe it has changed but I am not sure). One of this projects have at the end "service" and another "portlet" - project with "portlet" in the name it is a web project and build a WAR file - this WAR file should have a "portlet" in the name and You war does not have it, correct? Because I can see:
MyNewsletter-1.0.0.2


Best regards
Christian Berndt, modifié il y a 10 années.

RE: BeanLocator has not been set for servlet context

New Member Publications: 10 Date d'inscription: 23/02/12 Publications récentes
Yes - that's true - when you use the service-builder archetype, you end up with two maven projects. In 6.2.0, too.

But I started with the liferay-portlet-primefaces-archetype, 6.2.0-RC5, added a service.xml to the WEB-INF-dir and built the services with mvn liferay:build-service.

Do you think, this makes any difference? This approach worked for all my previous projects, which where based on the MVCPortlet.

Best, Christian
Christian Berndt, modifié il y a 10 années.

RE: BeanLocator has not been set for servlet context

New Member Publications: 10 Date d'inscription: 23/02/12 Publications récentes
Update:

only to exclude any errors, I tried to use my service classes with a jsp.

I was pretty sure, that this would work. But to my surprise, I encountered the same Beanlocator issue.

I will now try to build a service with the 2.0 IDE and deploy it against 6.2.0.

Any recommendations, which version I should use?

From central, there are still only the RC5 archetypes available.

Best, Christian
thumbnail
Juan Gonzalez, modifié il y a 10 années.

RE: BeanLocator has not been set for servlet context

Liferay Legend Publications: 3089 Date d'inscription: 28/10/08 Publications récentes
Hi Christian,

try to add the Liferay repository in your Maven repository list:

http://repository.liferay.com

There there should be all versions.

P.D.: of course much better if you use the 6.2.0-ga1 version.
Christian Berndt, modifié il y a 10 années.

RE: BeanLocator has not been set for servlet context

New Member Publications: 10 Date d'inscription: 23/02/12 Publications récentes
Hi Juan,
one step further, though I can't setup a working environment with 6.2.0-ga1 artifacts.
On a clean install with Liferay 6.2.0 RC5 with 6.2.0 RC artifacts from central I observe the following behaviour:

Custom entity generated with service-builder is working with:
- liferay-servicebuilder-archetype 6.2.0 RC

Same service.xml (with another namespace) with:
- liferay-portlet-archetype 6.2.0 RC (The one, I used for my 6.1.x projects)

Portlet fails with BeanlocatorException

The sequence of the build sequence was the same with both projects:

build-service package liferay:deploy

I conclude, there is an issue, with building services for non-servicebuilder-archetypes, at least with the 6.2.0 archetypes.

I will now try to setup a fresh enviroment with the 6.2.0 GA1 artifacts, following the setup instructions found at http://www.liferay.com/de/documentation/liferay-portal/6.2/development/-/ai/developing-plugins-using-maven-liferay-portal-6-2-dev-guide-02-en.

Best, Christian
Christian Berndt, modifié il y a 10 années.

RE: BeanLocator has not been set for servlet context

New Member Publications: 10 Date d'inscription: 23/02/12 Publications récentes
Hi Juan,

finally, I have managed to get the ga1 artifacts running. But some same behaviour:

If I use the liferay-servicebuilder-archetype and create my services, I can use the service-classes in my jsp.

If I use the liferay-portlet-archetype, create a service.xml myself and run mvn liferay:build-service package liferay deploy, I receive a BeanLocator exception.

Or is the second approach discouraged with 6.2.0?

Best, Christian
Paul Nergoght, modifié il y a 10 années.

RE: BeanLocator has not been set for servlet context

New Member Envoyer: 1 Date d'inscription: 04/01/14 Publications récentes
Hi,
I have the same problem. Have you solved it?
thumbnail
Juan Gonzalez, modifié il y a 10 années.

RE: BeanLocator has not been set for servlet context

Liferay Legend Publications: 3089 Date d'inscription: 28/10/08 Publications récentes
Hi Christian,

what do you mean by "replace"? Maybe that's the issue if this is not done using Liferay IDE for creating service builder entities.

Can you try creating that project from Liferay IDE as a normal Liferay JSF portlet (better with Liferay IDE 2.0 snapshot), and then in that project create Liferay Service Builder, so everything is being done from Liferay IDE.
Christian Berndt, modifié il y a 10 années.

RE: BeanLocator has not been set for servlet context

New Member Publications: 10 Date d'inscription: 23/02/12 Publications récentes
Hi Juan,

thanks for your quick response. With "replace" I mean:

I have a working implementation which uses the UserLocalService like the primefaces3-users-portlet example by Neil and Kyle. (In fact, a "copy and paste" implementation of their code in a fresh primefaces project using the 6.2.0-RC5 archetype.

As long, as I use Liferay's built-in services, the code is working.

But when I try to access my custom entity ("Newsletter" of "MyNewsletter"-portlet), I receive a "BeanLocator is null" message (see below).

11:01:40,149 ERROR [http-bio-8080-exec-36][PortletBeanLocatorUtil:42] BeanLocator is null for servlet context MyNewsletter
11:01:40,156 ERROR [NewsletterLazyDataModel:108] BeanLocator has not been set for servlet context MyNewsletter
com.liferay.portal.kernel.bean.BeanLocatorException: BeanLocator has not been set for servlet context MyNewsletter
at com.liferay.portal.kernel.bean.PortletBeanLocatorUtil.locate(PortletBeanLocatorUtil.java:46)
at com.wcs.newsletter.service.NewsletterLocalServiceUtil.getService(NewsletterLocalServiceUtil.java:610)

I don't believe, there is something wrong with the autog-generated code (I'm using Liferay IDE, version 1.6.2 on Debian Linux and the Maven SDK with the 6.2.0 archetypes).

I assume, it's more likely, that I missed some configuration required for liferay faces.

I have to admit, that this is my first faces project. In previous projects I used the MVCPortlet approach for the presentation layer.

Best, Christian