Skip to content

Instantly share code, notes, and snippets.

@martinlau
Created November 30, 2012 00:37
Show Gist options
  • Save martinlau/4172932 to your computer and use it in GitHub Desktop.
Save martinlau/4172932 to your computer and use it in GitHub Desktop.
Changes to spring configuration and liferay hook implementation leveraging aspectj weaving
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<context:spring-configured />
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>
<bean id="transactionManager" class="com.liferay.util.spring.transaction.TransactionManagerClp" init-method="init"/>
<bean id="portal" class="com.liferay.portal.util.PortalUtil" factory-method="getPortal" />
<bean id="userLocalService" class="com.liferay.portal.service.UserLocalServiceUtil" factory-method="getService" />
<bean id="fakeService" class="au.com.permeance.service.impl.FakeServiceImpl">
<constructor-arg index="0" name="portal" ref="portal" />
<constructor-arg index="1" name="userLocalService" ref="userLocalService" />
</bean>
</beans>
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import static org.springframework.beans.factory.annotation.Autowire.BY_TYPE;
@Configurable(autowire = BY_TYPE,
dependencyCheck = true)
public class StartupHookAction extends SimpleAction {
private FakeService fakeService;
@Autowired
public void setFakeService(final FakeService fakeService) {
this.fakeService = fakeService;
}
@Override
public void run(final String[] ids) throws ActionException {
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