Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Framework: Update all advices to use Springs @AspectJ support #141

Closed
tjuerge opened this issue Jul 29, 2014 · 1 comment
Closed

Framework: Update all advices to use Springs @AspectJ support #141

tjuerge opened this issue Jul 29, 2014 · 1 comment

Comments

@tjuerge
Copy link
Member

tjuerge commented Jul 29, 2014

As of Sculptor 3.0.4 only the PublishAdvice (introduced in 2010) is leveraging Springs @AspectJ support. Besides from being old-school this keeps us from using these advices with Springs Java config approach mentioned in #122.

@tjuerge tjuerge added this to the 3.1.0 milestone Jul 29, 2014
@tjuerge tjuerge added wontfix and removed 1 - Ready labels Dec 27, 2014
@tjuerge
Copy link
Member Author

tjuerge commented Dec 27, 2014

The other Sculptor advices (ServiceContextStoreAdvice, ErrorHandlingAdvice, BasicErrorHandlingAdvice and JpaFlushEagerAdvice) can't be used with Springs @AspectJ support because their pointcut is application specific. Here the name of the applications base package is needed in the AspectJ expression.

So we have to wrap these advices into a DefaultPointcutAdvisor (together with the corresponding AspectJExpressionPointcut) to create an advisor with Spring Java config, e.g.

@Configuration
public class AopConfig {

    @Pointcut("execution(public * org.sculptor.examples.library..serviceapi.*.*(..))")
    public void service() {
    }

    @Pointcut("execution(* get*(..)) || execution(* find*(..))")
    public void readOnlyMethod() {
    }

    @Bean
    public Advice serviceContextStoreAdvice() {
        return new ServiceContextStoreAdvice();
    }

    @Bean
    public Advice errorHandlingAdvice() {
        return new ErrorHandlingAdvice();
    }

    @Bean
    public Advice jpaFlushEagerAdvice() {
        return new JpaFlushEagerAdvice();
    }

    @Bean
    public Advisor serviceContextStoreAdvisor() {
        AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
        pointcut.setExpression("org.sculptor.examples.library.config.AopConfig.service()");
        DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor(pointcut, serviceContextStoreAdvice());
        advisor.setOrder(2);
        return advisor;
    }

    @Bean
    public Advisor errorHandlingAdvisor() {
        AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
        pointcut.setExpression("org.sculptor.examples.library.config.AopConfig.service()");
        DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor(pointcut, errorHandlingAdvice());
        advisor.setOrder(3);
        return advisor;
    }

    @Bean
    public Advisor jpaFlushEagerAdvisor() {
        AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
        pointcut.setExpression("org.sculptor.examples.library.config.AopConfig.service()  && !org.sculptor.examples.library.config.AopConfig.readOnlyMethod()");
        DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor(pointcut, jpaFlushEagerAdvice());
        advisor.setOrder(4);
        return advisor;
    }

}

@tjuerge tjuerge closed this as completed Dec 27, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant