Solon

B、注解处理注册的合适时机点

</> markdown

一个注解会被启用,是因为容器扫描时对它们做了处理。所有要注册一个注解的能力,必须要在容器扫描开始之前完成。

1、应用生命周期

开发自定义注解,了解此图非常重要。须要在[时机点9]之前,完成注解的能力注册。

2、合适的可控时机点

  • 比如,时机点5
public class DemoApp{
    public void static main(String[] args){
        Solon.start(DemoApp.clas, args, app->{
            //...时机点5
            app.context().beanInterceptorAdd(DemoAop.class, new DemoInterceptor());
        });
    }
}
  • 比如,时机点6(借用 SolonBuilder,提前注册事件)
public class DemoApp{
    public void static main(String[] args){
        new SolonBuilder().onAppInitEnd(e -> {
            //...时机点6
        }).onAppLoadEnd(e->{
            //...时间点e          
        }).start(JobApp.class, args);
    }
}

定义一个插件

public class DemoPluginImp implements Plugin {
    @Override
    public void start(AppContext context) {
        //..时机点7
        context.beanInterceptorAdd(DemoAop.class, new DemoInterceptor());
    }
}

通过插件申明配置,借用[时机点4]申明插件

solon.plugin=xxx.xxx.DemoPluginImp