Q:

Liferay - Autologin hook + Spring integration

I'm trying to integrate Spring container with my custom AutoLogin filter, but I've spent two days with that and it's not working yet...I'm really confused at this time...
My custom AutoLogin needs to authenticate agains an external database, diferent from the Liferay, so what I pretend is to use my service and Daos configured in Spring to archive this. 
My web.xml has this configuration:
<context-param>
     <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring/applicationContext.xml</param-value>
</context-param>

 <context-param>
    <param-name>portalContextConfigLocation</param-name>

    <param-value>
        /WEB-INF/spring/applicationContext.xml
    </param-value>
</context-param>

 <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<listener>
    <listener-class>com.liferay.portal.kernel.spring.context.PortletContextLoaderListener</listener-class>

but I'm really not sure if I need both listerenrs or just one of them. 
When the hook initializes, no Spring classes could be found in classpath, so I added required libraries to the Tomcat/lib directory. Liferay has its own classloder and It seems that the hook it's not able to see the Liferay Classloader...so no classes can be found in classpath.
But the big problem was that I could not add the Hibernate-core jar to server classpath, because it causes a CastingException when the server starts up.
Another test I've done, was to add the Hibernate jar to the WEB-INF/lib folder of my Hook, but it's like no Jar is loaded in the Hook classloader...so it doesn't work neither. 
Please, any help will be appreciated...I hope is a configuration problem...althought I've been playing moving Jars, It should be easier, doesn't it? 
Thank you very much in advance!
Ivan

A:

I've finally solved my Spring integration...Just for people with the same issue, here is what I've done:

Update the property "portal-dependency-jars" in file "liferay-plugin-package.properties" with all required libraries from Liferay:

portal-dependency-jars=\
  commons-logging.jar,\
  hibernate3.jar,\
  log4j-extras.jar,\
  log4j.jar,\
  spring-aop.jar,\
  spring-asm.jar,\
  spring-aspects.jar,\
  spring-beans.jar,\
  spring-context-support.jar,\
  spring-context.jar,\
  spring-core.jar,\
  spring-expression.jar,\
  spring-jdbc.jar,\
  spring-jms.jar,\
  spring-orm.jar,\
  spring-oxm.jar,\
  spring-transaction.jar,\
  spring-web-portlet.jar,\
  spring-web-servlet.jar,\
  spring-web-struts.jar,\
  spring-web.jar,\
  aopalliance.jar,\
  dom4j.jar,\
  slf4j-api.jar,\
  commons-beanutils.jar,\
  commons-collections.jar,\
  commons-lang.jar,\
  concurrent.jar,\
  javassist.jar

Leave the web.xml without any Spring Listener. I finally couldn't load the Spring context from the listeners...  
Load the Spring container in your hook using the ClassPathXmlApplicationContext class.

Using this configuration, you don't need to copy any Jar into the tomcat/lib directory.
I hope this can help to somebody!
Ivan Fontanals

