001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.spring.context;
016    
017    import com.liferay.portal.kernel.portlet.PortletClassLoaderUtil;
018    import com.liferay.portal.kernel.util.AggregateClassLoader;
019    import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
020    import com.liferay.portal.spring.util.FilterClassLoader;
021    
022    import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
023    import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
024    
025    /**
026     * @author Brian Wing Shun Chan
027     */
028    public class PortletBeanFactoryPostProcessor
029            implements BeanFactoryPostProcessor {
030    
031            public void postProcessBeanFactory(
032                    ConfigurableListableBeanFactory beanFactory) {
033    
034                    ClassLoader beanClassLoader =
035                            AggregateClassLoader.getAggregateClassLoader(
036                                    new ClassLoader[] {
037                                            PortletClassLoaderUtil.getClassLoader(),
038                                            PortalClassLoaderUtil.getClassLoader()
039                                    });
040    
041                    beanClassLoader = new FilterClassLoader(beanClassLoader);
042    
043                    beanFactory.setBeanClassLoader(beanClassLoader);
044            }
045    
046    }