Created
November 30, 2012 00:29
-
-
Save martinlau/4172896 to your computer and use it in GitHub Desktop.
A hook which uses an external spring context to enter into spring managed transactions and dependency injection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package au.com.permeance.hook; | |
import au.com.permeance.service.FakeService; | |
import com.liferay.portal.kernel.events.ActionException; | |
import com.liferay.portal.kernel.events.SimpleAction; | |
import com.liferay.portal.kernel.servlet.ServletContextPool; | |
import org.springframework.beans.factory.BeanFactory; | |
import org.springframework.web.context.support.WebApplicationContextUtils; | |
import javax.servlet.ServletContext; | |
public class StartupHookAction extends SimpleAction { | |
@Override | |
public void run(final String[] ids) throws ActionException { | |
ServletContext servletContext = ServletContextPool.get("spring-hook"); | |
BeanFactory beanFactory = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); | |
FakeService fakeService = beanFactory.getBean(FakeService.class); | |
try { | |
fakeService.doStuff(); | |
} | |
catch (Exception e) { | |
throw new ActionException(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment