为什么Play 1和Play 2之间的`插件'的基类如此不同?

时间:2012-04-02 09:20:57

标签: plugins playframework playframework-2.0

Play 1中的插件基类是play.PlayPlugin,它有很多方法(字段):

index : int
onLoad()
compileSources()
runTest(Class<BaseTest>)
bind(String, Class, Type, Annotation[], Map<String, String[]>)
bind(RootParamNode, String, Class<?>, Type, Annotation[])
bind(String, Object, Map<String, String[]>)
bindBean(RootParamNode, String, Object)
unBind(Object, String)
getMessage(String, Object, Object...)
getStatus()
getJsonStatus()
enhance(ApplicationClass)
onTemplateCompilation(Template)
rawInvocation(Request, Response)
serveStatic(VirtualFile, Request, Response)
beforeDetectingChanges()
loadTemplate(VirtualFile)
detectChange()
detectClassesChange()
onApplicationStart()
afterApplicationStart()
onApplicationStop()
beforeInvocation()
afterInvocation()
onInvocationException(Throwable)
invocationFinally()
beforeActionInvocation(Method)
onActionInvocationResult(Result)
onInvocationSuccess()
onRequestRouting(Route)
afterActionInvocation()
onConfigurationRead()
onRoutesLoaded()
onEvent(String, Object)
onClassesChange(List<ApplicationClass>)
addTemplateExtensions()
addMimeTypes()
compileAll(List<ApplicationClass>)
routeRequest(Request)
modelFactory(Class<? extends Model>)
afterFixtureLoad()
postEvent(String, Object)
onApplicationReady()
compareTo(PlayPlugin)
overrideTemplateSource(BaseTemplate, String)
willBeValidated(Object)

Play 2是play.api.Plugin,非常简单:

onStart(): Unit
onStop(): Unit
enabled: Boolean

为什么他们如此不同?而且我认为Play 1的插件类中的方法被定义为extension-points,对于Play 2它们是不是不再需要它们了?

1 个答案:

答案 0 :(得分:1)

Play 2.0区分全局设置插件

Global settings特定于应用程序,并允许自定义框架的某些行为(例如,如果没有找到请求的操作,应该怎么做)。实际上Play 1.x插件的大多数扩展点现在都在Play 2.x全局设置中。

Plugins是可能需要了解应用程序生命周期以执行初始化/清理操作的模块。