问题
I would like to include AspectJ-Weaving in a Play (2.2.1) project.
I only found one answer explaining how to add AspectJ to Play (2.1.1) projects.
In version 2.2.1 however the project layout changed and there is no Build.scala anymore. In its place build.sbt files are used in newer projects.
Can anyone tell me how to add AspectJ to new Play projects?
Update:
I tried using AspectJ in a Play 2.1.3 project using the configuration provided in the link above. I did in fact get play to compile and run the project. When running the application I see log output from AspectJ in the console:
--- (Running the application from SBT, auto-reloading is enabled) ---
[info] play - Listening for HTTP on /0:0:0:0:0:0:0:0:9000
(Server started, use Ctrl+D to stop and go back to the console...)
[info] Weaving 1 input with 2 AspectJ binaries to C:\Users\myName\Desktop\tmp\
oldPlayAopTest\target\scala-2.10\aspectj\classes...
[info] info directory classpath entry does not exist: C:\Program Files\Java\jre7
\lib\sunrsasign.jar
[info] info zipfile classpath entry does not exist: C:\Program Files\Java\jre7\c
lasses
[info] info Pipelining compilation
[info] info weaver operating in reweavable mode. Need to verify any required ty
pes exist.
[info] info woven class views.html.index$$anonfun$f$1 (from C:\Users\myName\De
sktop\tmp\oldPlayAopTest\target\scala-2.10\classes\views\html\index$$anonfun$f$1
.class)
[info] info woven class controllers.ReverseApplication (from C:\Users\myName\D
esktop\tmp\oldPlayAopTest\target\scala-2.10\classes\controllers\ReverseApplicati
on.class)
[info] info woven class views.html.main$$anonfun$f$1$$anonfun$apply$1 (from C:\U
sers\myName\Desktop\tmp\oldPlayAopTest\target\scala-2.10\classes\views\html\ma
in$$anonfun$f$1$$anonfun$apply$1.class)
[info] info woven class controllers.javascript.ReverseApplication (from C:\Users
\myName\Desktop\tmp\oldPlayAopTest\target\scala-2.10\classes\controllers\javas
cript\ReverseApplication.class)
[info] info woven class Routes (from C:\Users\myName\Desktop\tmp\oldPlayAopTes
t\target\scala-2.10\classes\Routes.class)
[info] info woven class views.html.index (from C:\Users\myName\Desktop\tmp\old
PlayAopTest\target\scala-2.10\classes\views\html\index.class)
[info] info woven class controllers.routes (from C:\Users\myName\Desktop\tmp\o
ldPlayAopTest\target\scala-2.10\classes\controllers\routes.class)
[info] info woven class controllers.ReverseAssets (from C:\Users\myName\Deskto
p\tmp\oldPlayAopTest\target\scala-2.10\classes\controllers\ReverseAssets.class)
[info] info woven class controllers.routes$javascript (from C:\Users\myName\De
sktop\tmp\oldPlayAopTest\target\scala-2.10\classes\controllers\routes$javascript
.class)
[info] info woven class Routes$$anonfun$routes$1$$anonfun$applyOrElse$2 (from C:
\Users\myName\Desktop\tmp\oldPlayAopTest\target\scala-2.10\classes\Routes$$ano
nfun$routes$1$$anonfun$applyOrElse$2.class)
[info] info woven class controllers.routes$ref (from C:\Users\myName\Desktop\t
mp\oldPlayAopTest\target\scala-2.10\classes\controllers\routes$ref.class)
[info] info woven class controllers.ref.ReverseAssets$$anonfun$at$1 (from C:\Use
rs\myName\Desktop\tmp\oldPlayAopTest\target\scala-2.10\classes\controllers\ref
\ReverseAssets$$anonfun$at$1.class)
[info] info woven class Routes$$anonfun$routes$1 (from C:\Users\myName\Desktop
\tmp\oldPlayAopTest\target\scala-2.10\classes\Routes$$anonfun$routes$1.class)
[info] info woven class Routes$ (from C:\Users\myName\Desktop\tmp\oldPlayAopTe
st\target\scala-2.10\classes\Routes$.class)
[info] info woven class controllers.ref.ReverseApplication (from C:\Users\nwinkl
er\Desktop\tmp\oldPlayAopTest\target\scala-2.10\classes\controllers\ref\ReverseA
pplication.class)
[info] info woven class Routes$$anonfun$setPrefix$1 (from C:\Users\myName\Desk
top\tmp\oldPlayAopTest\target\scala-2.10\classes\Routes$$anonfun$setPrefix$1.cla
ss)
[info] info woven class controllers.ref.ReverseAssets (from C:\Users\myName\De
sktop\tmp\oldPlayAopTest\target\scala-2.10\classes\controllers\ref\ReverseAssets
.class)
[info] info woven class Routes$$anonfun$routes$1$$anonfun$applyOrElse$1$$anonfun
$apply$1 (from C:\Users\myName\Desktop\tmp\oldPlayAopTest\target\scala-2.10\cl
asses\Routes$$anonfun$routes$1$$anonfun$applyOrElse$1$$anonfun$apply$1.class)
[info] info woven class views.html.main (from C:\Users\myName\Desktop\tmp\oldP
layAopTest\target\scala-2.10\classes\views\html\main.class)
[info] info woven class models.TestEntity (from C:\Users\myName\Desktop\tmp\ol
dPlayAopTest\target\scala-2.10\classes\models\TestEntity.class)
[info] info woven class Routes$$anonfun$routes$1$$anonfun$applyOrElse$1 (from C:
\Users\myName\Desktop\tmp\oldPlayAopTest\target\scala-2.10\classes\Routes$$ano
nfun$routes$1$$anonfun$applyOrElse$1.class)
[info] info woven class controllers.ref.ReverseApplication$$anonfun$index$1 (fro
m C:\Users\myName\Desktop\tmp\oldPlayAopTest\target\scala-2.10\classes\control
lers\ref\ReverseApplication$$anonfun$index$1.class)
[info] info woven class Routes$$anonfun$documentation$1 (from C:\Users\myName\
Desktop\tmp\oldPlayAopTest\target\scala-2.10\classes\Routes$$anonfun$documentati
on$1.class)
[info] info woven class Routes$$anonfun$routes$1$$anonfun$applyOrElse$2$$anonfun
$apply$2 (from C:\Users\myName\Desktop\tmp\oldPlayAopTest\target\scala-2.10\cl
asses\Routes$$anonfun$routes$1$$anonfun$applyOrElse$2$$anonfun$apply$2.class)
cala-2.10
$2.class)
However the advice specified in aspects/AspectTest.aj is not being applied to my controller method (the advice functionality is not being called).
Advice
public aspect AspectTest {
before() : call(play.mvc.Result controllers.Application.index()) {
Logger.info("aspect");
}
}
Controller method
public static Result index() {
return ok("hello");
}
Do I have to specify the advices and/or classes the advices should be used on?
来源:https://stackoverflow.com/questions/22780051/aspectj-in-play-framework-2-2-1-java