Magician-Containers 正在参加 2021 年度 OSC 中国开源项目评选,请投票支持!
Magician-Containers 在 2021 年度 OSC 中国开源项目评选 中已获得 {{ projectVoteCount }} 票,请投票支持!
2021 年度 OSC 中国开源项目评选 正在火热进行中,快来投票支持你喜欢的开源项目!
2021 年度 OSC 中国开源项目评选 >>> 中场回顾
Magician-Containers 获得 2021 年度 OSC 中国开源项目评选「最佳人气项目」 !
授权协议 MIT
开发语言 Java
操作系统 跨平台
软件类型 开源软件
所属分类 云计算PaaS系统/容器
开源组织
地区 国产
投 递 者 Magician开源
适用人群 未知
收录时间 2022-07-13

软件简介

Magician-Containers 是 Magician 的官方组件,一个容器管理模块,可以对项目中的bean进行统一管理,它带来了两个扩展:AOP 和定时任务。

文档

https://magician-io.com

示例

导入依赖

<!-- 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>

标记Bean

不可以用在Controller上

@MagicianBean
public class DemoBean {

}

Aop

编写AOP的逻辑

public class DemoAop implements BaseAop {

    /**
     * 方法执行前
     * @param args 方法的参数
     */
    public void startMethod(Object[] args) {

    }

    /**
     * 方法执行后
     * @param args 方法的参数
     * @param result 方法的返回数据
     */
    public void endMethod(Object[] args, Object result) {

    }

    /**
     * 方法出异常后
     * @param e 方法的异常信息
     */
    public void exp(Throwable e) {

    }
}

挂到需要监听的方法上

@MagicianBean
public class DemoBean {

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

    }
}

定时任务

@MagicianBean
public class DemoBean {

    // loop: 轮训频率,单位:毫秒
    @MagicianTimer(loop=1000)
    public void demoTimerMethod() {

    }
}

获取Bean对象

@MagicianBean
public class DemoBean {

    private DemoBean demoBean;

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

启动时加载资源

HttpServer httpServer = Magician
        .createHttp()
        .scan("com.test"); // Scanning range (package name)

// 在scan方法执行后,才可以加载bean,顺序一定要注意
MagicianContainers.load();

httpServer.bind(8080);

 

展开阅读全文

代码

的 Gitee 指数为
超过 的项目

评论

点击引领话题📣 发布并加入讨论🔥
暂无内容
发表了博客
{{o.pubDate | formatDate}}

{{formatAllHtml(o.title)}}

{{parseInt(o.replyCount) | bigNumberTransform}}
{{parseInt(o.viewCount) | bigNumberTransform}}
没有更多内容
暂无内容
发表了问答
{{o.pubDate | formatDate}}

{{formatAllHtml(o.title)}}

{{parseInt(o.replyCount) | bigNumberTransform}}
{{parseInt(o.viewCount) | bigNumberTransform}}
没有更多内容
暂无内容
暂无内容
0 评论
6 收藏
分享
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部