我想在Play(2.2.1)项目中加入AspectJ-Weaving。
我只找到一个答案,解释如何add AspectJ to Play (2.1.1) projects。
在版本2.2.1中,项目布局已更改,并且不再有Build.scala。 取而代之的是build.sbt文件用于较新的项目。
有谁能告诉我如何将AspectJ添加到新的Play项目中?
更新
我尝试使用上面链接中提供的配置在Play 2.1.3项目中使用AspectJ。 事实上我做了编译和运行项目的游戏。运行应用程序时,我在控制台中看到AspectJ的日志输出:
--- (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)
然而,在aspect / AspectTest.aj中指定的建议未应用于我的控制器方法(不会调用建议功能)。
建议
public aspect AspectTest {
before() : call(play.mvc.Result controllers.Application.index()) {
Logger.info("aspect");
}
}
控制器方法
public static Result index() {
return ok("hello");
}
我是否必须指定建议应该使用的建议和/或类?