SpringSource/spring-scala — pull request #7 by hekonsek (2013-02-02 13:23:02+00:00)
Title: Proposal of basic AOP DSL

Hi,

Spring comes with a pretty support for AOP configuration via XML DSL. Since Scala provides amazing DSL capabilities, it will be a true shame not to create Scala DSL for AOP as well.

I created simple AOP DSL enclosed within the `AopSupport` trait. Under the hood it creates `ProxyFactoryBean` configured with the `DefaultPointcutAdvisors`.

class TestConfiguration extends FunctionalConfiguration with AopSupport {

// Define some pointcuts and advices.
val pointcut = (m: Method, c: Class[_]) => m.getName == "toString"
val beforeAdvice = (m: Method, args: Array[AnyRef], target: Any) => { println("Before!") }

// You can wrap existing bean into AOP proxy.
bean("myService")(new MyService)
advice targetRef "myService" on pointcut using beforeAdvice

// Or create proxy over embedded POJO.
advice target (new MyService) on pointcut using beforeAdvice

// You can name the proxy and apply multiple advises to it as well.
advice(beanName = "myService").target(new MyService).
on(pointcat).using(beforeAdvice).
on(someOtherPointcut).using(afterAdvice)

}

Actually many interesting things can be done in the area of Scala DSL for Spring AOP. This is the minimal usable part of it.

Of course if you like this pull request, I can create Scaladoc for it as well.

Best regards.