samedi 27 octobre 2012

Liferay : how to fix NoSuchBeanDefinitionException while portlet deploying

I would like to share the fix for mysterious and annoying issue that I've encountered during the development and deploying of a portlet for Liferay 5.2.3.

The error that Liferay server (Tomact) listed in the logs was related to misconfigured Spring beans and the exception was org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'my.service.persistence.SynergieCategoryPersistence.impl' is defined 
The partial stacktrace is belows:

16:36:12,700 ERROR [PortalClassLoaderServletContextListener:92] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'my.service.SynergieCategoryLocalService.impl': Injection of BeanReference fields failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'my.service.persistence.SynergieCategoryPersistence.impl' is defined
org.springframework.beans.factory.BeanCreationException: Error creating bean with name '': Injection of BeanReference fields failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'my.service.persistence.SynergieCategoryPersistence.impl' is defined
 at com.liferay.portal.spring.annotation.BeanReferenceAnnotationBeanPostProcessor.postProcessAfterInstantiation(
 at Method)
 at org.springframework.web.context.ContextLoader.createWebApplicationContext(
 at org.springframework.web.context.ContextLoader.initWebApplicationContext(
 at org.springframework.web.context.ContextLoaderListener.contextInitialized(
 at com.liferay.portal.spring.context.PortletContextLoaderListener.contextInitialized(
 at com.liferay.portal.kernel.servlet.PortalClassLoaderServletContextListener.portalInit(
 at com.liferay.portal.kernel.util.PortalInitableUtil.init(
 at com.liferay.portal.kernel.servlet.PortalClassLoaderServletContextListener.contextInitialized(
 at org.apache.catalina.core.StandardContext.listenerStart(
 at org.apache.catalina.core.StandardContext.start(
 at org.apache.catalina.core.ContainerBase.addChildInternal(
 at org.apache.catalina.core.ContainerBase.addChild(
 at org.apache.catalina.core.StandardHost.addChild(
 at org.apache.catalina.startup.HostConfig.deployDirectory(
 at org.apache.catalina.startup.HostConfig.deployDirectories(
 at org.apache.catalina.startup.HostConfig.deployApps(
 at org.apache.catalina.startup.HostConfig.check(
 at org.apache.catalina.startup.HostConfig.lifecycleEvent(
 at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(
 at org.apache.catalina.core.ContainerBase.backgroundProcess(
 at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(
 at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(
 at org.apache.catalina.core.ContainerBase$
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'my.service.persistence.SynergieCategoryPersistence.impl' is defined
 at com.liferay.portal.bean.BeanLocatorImpl.locate(
 at com.liferay.portal.kernel.bean.PortalBeanLocatorUtil.locate(
 at com.liferay.portal.spring.annotation.BeanReferenceElement.getResourceToInject(
 at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(
 at org.springframework.beans.factory.annotation.InjectionMetadata.injectFields(
 at com.liferay.portal.spring.annotation.BeanReferenceAnnotationBeanPostProcessor.postProcessAfterInstantiation(
 ... 36 more

The portlet classes have been generated by build-service and the same code worked fine during last 2 years. So I was pretty sure that my Spring config is OK and the problem resides in the other part of the system.

After few days spent in debug mode, I have found that while deploying the portlet, the folder WEB-INF/lib was missing the jar file util-java.jar.
Obviously, util-java.jar is needed by Liferay to make some stuff. And apparently, in my case, this jar have not been copied automatically by Liferay hot deployer.

I have copied the missing util-java.jar to WEB-INF/lib and portlet has been deployed without any error.

mardi 8 mai 2012

Software Industrialization presentation

Few days ago I had to make a presentation about the software industrialization approaches at Octetis (the international IT company for whom I'm currently working).

The result is here - one page PDF document:

The one thing to share is about very beautiful and complete Project Gallery from MS Word for Mac.

All styles, fonts, document structure, etc. were available out of the box. All the other stuff was created using PowerPoint for Mac as well.

Merci Microsoft & Apple.

jeudi 9 février 2012

Maven BuildNumber plugin - short revision id for Git

Today, I would like to explain the improvement for maven plugin - buildNumber, that I talked in my previous message - short revision id for Git SCM.

IMPORTANT : This feature is present in the maven-buildnumber-plugin 1.1 version.

You can specify the length for the Git revision. To enable this feature you have to specify the new tag
in the
section. For exemple:

The associated maven output informs us about the detection of shortRevisionLength tag and print the length of the revision that will be used in buildNumber formatting:

Some implementation details

This feature uses internally the git rev-pasre --short (see associated git help section) command and the revision length is set to minimum 4 characters. So you can't have the revision id shorter then 4 characters. Even if you specify the length between 0 and 4, the plugin will inform you about this situation and the minimum value (4) will be used.

UPDATED: If your maven build can't find the dependency for maven-buildnumber-plugin 1.1 , try to force the dependency update  by adding option "-U" for your mvn command.

mercredi 8 février 2012

My first Open Source commitment - Git short revision

Today, my patches for 2 maven projects have been accepted by the maven-buildNumber-plugin's project lead Olivier Lamy.

One of the web Java project, I currently working on, is fully automated with Maven. One interesting and useful thing is to have the date & the revision number at the bottom of the web page. Like this:
It was done with excellent maven plugin buildNumber -

The problem was that the project SCM migrated from the SVN to Git. And the revision ID in Git is too long. In fact it's SHA-1 sequence that should be unique across the world and all possible revisions... So the build id at the bottom of the page was so ugly for business users that I receive the task to make it shorter.

After asking the question about the git short revision id in and in the user's mailing lists of the maven, I understood that the buildNumber plugin does not support this feature. And the project Lead, Olivier Lamy, gracefully proposed to me to make a patch and pointed out the first java class I have to look at.
The code he sent me was very clear and I quickly figured out how to add the new feature that I called shortRevisionLength.
After one day of working I have sent the patch to Olivier and created 2 issues on the codehouse JIRA server:
I added some test cases and the documentation patch as well.

The next day the patch has been approved and integrated in the SVN. So, the next version of buildNumber plugin 1.1 contains some peace of code from Ukraine :) Nice.

jeudi 12 janvier 2012

Install Pear on Windows 7

Just a little tips about installing PEAR for PHP on Windows 7.

I have spent 3 hours today to install PEAR on Windows. I had systematically the error, when I was trying to execute config-set auto_discover 1 in the CMD:
PEAR_Config::writeConfigFile fopen('C:/Windows/pear.ini', 'w') failed... permission denied

It was clear that the problem in the PEAR installation - the location of pear.ini file was wrong. It's important to note, that all installation and manipulation with pear I made with basic CMD.

If you have the same problems, you have to reinstall your PEAR with PowerShell.
With PowerShell the pear.ini is in the PHP folder and it will fixe all the problems