<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Magician-Containers容器管理模塊

          聯(lián)合創(chuàng)作 · 2023-09-27 16:08

          Magician-Containers 是 Magician 的官方組件,一個(gè)容器管理模塊,可以對(duì)項(xiàng)目中的bean進(jìn)行統(tǒng)一管理,它帶來了兩個(gè)擴(kuò)展:AOP 和定時(shí)任務(wù)。

          文檔

          https://magician-io.com

          示例

          導(dǎo)入依賴

          <!-- This is the jar package build by this project -->
          <dependency>
              <groupId>com.magician.containers</groupId>
              <artifactId>Magician-Containers</artifactId>
              <version>1.0.0</version>
          </dependency>
          
          <!-- This is Magician -->
          <dependency>
              <groupId>com.github.yuyenews</groupId>
              <artifactId>Magician</artifactId>
              <version>2.0.5</version>
          </dependency>
          
          <!-- This is the log package, which supports any package that can be bridged with slf4j -->
          <dependency>
              <groupId>org.slf4j</groupId>
              <artifactId>slf4j-jdk14</artifactId>
              <version>1.7.12</version>
          </dependency>

          標(biāo)記Bean

          不可以用在Controller上

          @MagicianBean
          public class DemoBean {
          
          }

          Aop

          編寫AOP的邏輯

          public class DemoAop implements BaseAop {
          
              /**
               * 方法執(zhí)行前
               * @param args 方法的參數(shù)
               */
              public void startMethod(Object[] args) {
          
              }
          
              /**
               * 方法執(zhí)行后
               * @param args 方法的參數(shù)
               * @param result 方法的返回?cái)?shù)據(jù)
               */
              public void endMethod(Object[] args, Object result) {
          
              }
          
              /**
               * 方法出異常后
               * @param e 方法的異常信息
               */
              public void exp(Throwable e) {
          
              }
          }

          掛到需要監(jiān)聽的方法上

          @MagicianBean
          public class DemoBean {
          
              @MagicianAop(className = DemoAop.class)
              public void demoAopMethod() {
          
              }
          }

          定時(shí)任務(wù)

          @MagicianBean
          public class DemoBean {
          
              // loop: 輪訓(xùn)頻率,單位:毫秒
              @MagicianTimer(loop=1000)
              public void demoTimerMethod() {
          
              }
          }

          獲取Bean對(duì)象

          @MagicianBean
          public class DemoBean {
          
              private DemoBean demoBean;
          
              public void demoMethod() {
                  demoBean = BeanUtil.get(DemoBean.class);
              }
          }

          啟動(dòng)時(shí)加載資源

          HttpServer httpServer = Magician
                  .createHttp()
                  .scan("com.test"); // Scanning range (package name)
          
          // 在scan方法執(zhí)行后,才可以加載bean,順序一定要注意
          MagicianContainers.load();
          
          httpServer.bind(8080);

           

          瀏覽 23
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  国产精品久久一区二区三区影音先锋 | 亚洲中文字幕视频在线观看 | 日本三级韩国三级欧美三级 | 黄色大片免费在线观看 | 操操操免费视频 |