Skip to content

Commit

Permalink
添加 solon Component:registered,控制形态注册
Browse files Browse the repository at this point in the history
  • Loading branch information
noear committed Jul 5, 2024
1 parent 53b22eb commit 353199d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
1 change: 1 addition & 0 deletions UPDATE_LOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* 添加 solon RouterInterceptor::postArguments 提交参数确认(更方便 mvc 参数定制)
* 添加 solon UploadedFile::getContentAsBytes 方法
* 添加 solon DownloadedFile 动态 304 的支持
* 添加 solon Component:registered,控制形态注册
* 添加 solon.data 序列化新实例 JsonSerializer.typedInstance
* 优化 solon `solon.config.load` 支持 `classpath:` 前缀
* 优化 solon.data 的 JsonSerializer,JavabinSerializer 类加载器处理
Expand Down
5 changes: 5 additions & 0 deletions solon/src/main/java/org/noear/solon/annotation/Bean.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
* */
int index() default 0;

/**
* 要注册的(能力接口)
*/
boolean registered() default true;

/**
* 要注入的
* */
Expand Down
13 changes: 9 additions & 4 deletions solon/src/main/java/org/noear/solon/annotation/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,21 @@

/**
* 标签,用于快速查找
* */
*/
String tag() default "";

/**
* 同时注册类型,仅当名称非空时有效
* */
*/
boolean typed() default false;

/**
* 排序(只对部分类型有效)
* */
*/
int index() default 0;
}

/**
* 要注册的(能力接口)
*/
boolean registered() default true;
}
16 changes: 10 additions & 6 deletions solon/src/main/java/org/noear/solon/core/AppContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ protected void initialize() {
//确定顺序位
bw.indexSet(anno.index());

beanComponentized(bw);
beanComponentized(bw, anno.registered());
});

//注册 @ProxyComponent 构建器 //@deprecated 2.5
Expand All @@ -195,7 +195,7 @@ protected void initialize() {
bw.indexSet(anno.index());

//组件化处理
beanComponentized(bw);
beanComponentized(bw, true);

LogUtil.global().error("@ProxyComponent will be discarded, suggested use '@Component'");
});
Expand All @@ -222,12 +222,14 @@ protected void initialize() {
/**
* 组件化处理
*/
protected void beanComponentized(BeanWrap bw) {
protected void beanComponentized(BeanWrap bw, boolean registered) {
//尝试提取函数并确定自动代理
beanExtractOrProxy(bw);

//添加bean形态处理
beanShapeRegister(bw.clz(), bw, bw.clz());
if (registered) {
beanShapeRegister(bw.clz(), bw, bw.clz());
}

//注册到容器
beanRegister(bw, bw.name(), bw.typed());
Expand Down Expand Up @@ -810,7 +812,7 @@ protected void tryBuildBean0(MethodWrap mWrap, Bean anno, Object raw) {
if (raw instanceof BeanWrap) {
m_bw = (BeanWrap) raw;
} else {
if(anno.injected()){
if (anno.injected()) {
//执行注入
beanInject(raw);
}
Expand All @@ -832,7 +834,9 @@ protected void tryBuildBean0(MethodWrap mWrap, Bean anno, Object raw) {
m_bw.indexSet(anno.index());

//添加bean形态处理
beanShapeRegister(m_bw.clz(), m_bw, mWrap.getMethod());
if (anno.registered()) {
beanShapeRegister(m_bw.clz(), m_bw, mWrap.getMethod());
}

//注册到容器
beanRegister(m_bw, beanName, anno.typed());
Expand Down

0 comments on commit 353199d

Please sign in to comment.