Magicia-Cotaiers是Magicia的官方组件,一个容器管理模块,可以对项目中的bea进行统一管理,它带来了两个扩展:AOP和定时任务。
文档https://magicia-io.com示例导入依赖<!--Thisisthejarpackagebuildbythisproject--><depedecy><groupId>com.magicia.cotaiers</groupId><artifactId>Magicia-Cotaiers</artifactId><versio>1.0.0</versio></depedecy><!--ThisisMagicia--><depedecy><groupId>com.github.yuyeews</groupId><artifactId>Magicia</artifactId><versio>2.0.5</versio></depedecy><!--Thisisthelogpackage,whichsupportsaypackagethatcabebridgedwithslf4j--><depedecy><groupId>org.slf4j</groupId><artifactId>slf4j-jdk14</artifactId><versio>1.7.12</versio></depedecy>标记Bea不可以用在Cotroller上@MagiciaBeapublicclassDemoBea{}Aop编写AOP的逻辑publicclassDemoAopimplemetsBaseAop{/***方法执行前*@paramargs方法的参数*/publicvoidstartMethod(Object[]args){}/***方法执行后*@paramargs方法的参数*@paramresult方法的返回数据*/publicvoidedMethod(Object[]args,Objectresult){}/***方法出异常后*@parame方法的异常信息*/publicvoidexp(Throwablee){}}挂到需要监听的方法上@MagiciaBeapublicclassDemoBea{@MagiciaAop(className=DemoAop.class)publicvoiddemoAopMethod(){}}定时任务@MagiciaBeapublicclassDemoBea{//loop:轮训频率,单位:毫秒@MagiciaTimer(loop=1000)publicvoiddemoTimerMethod(){}}获取Bea对象@MagiciaBeapublicclassDemoBea{privateDemoBeademoBea;publicvoiddemoMethod(){demoBea=BeaUtil.get(DemoBea.class);}}启动时加载资源HttpServerhttpServer=Magicia.createHttp().sca("com.test");//Scaigrage(packageame)//在sca方法执行后,才可以加载bea,顺序一定要注意MagiciaCotaiers.load();httpServer.bid(8080);
评论