Skip to content

Commit 26e5cf7

Browse files
committed
修复 solon AppContext:tryBuildBeanOfClass2 目标组件为接口时出现 getCreator null 异常
1 parent 3685285 commit 26e5cf7

File tree

4 files changed

+58
-7
lines changed

4 files changed

+58
-7
lines changed

UPDATE_LOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
### v3.7.1
3131

3232
* 添加 solon Router:add(clz) 方法
33-
* 修复 solon AppContext:tryBuildBeanOfClass2 出现 getCreator 异常的问题
33+
* 修复 solon AppContext:tryBuildBeanOfClass2 目标组件为接口时出现 getCreator null 异常
3434

3535
### 3.7.0
3636

solon/src/main/java/org/noear/solon/core/AppContext.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,20 +1073,23 @@ private int tryBuildBeanOfClass1(Class<?> clz) {
10731073
private void tryBuildBeanOfClass2(Class<?> clz, BeanBuilder builder, Annotation anno) throws Throwable {
10741074
ClassEggg clzEggg = EgggUtil.getClassEggg(clz);
10751075

1076-
if (clzEggg.getCreator() == null || clzEggg.getCreator().getParamCount() == 0) {
1076+
if (clzEggg.getCreator() == null) {
1077+
//没有(可能是接口)
10771078
tryBuildBeanOfClass3(clz, builder, anno, null, null);
1079+
} else if (clzEggg.getCreator().getParamCount() == 0) {
1080+
//默认构造方法
1081+
tryBuildBeanOfClass3(clz, builder, anno, (Constructor) clzEggg.getCreator().getConstr(), new Object[0]);
10781082
} else {
1079-
//包装(处理泛型参数)
1083+
//有参数的构造方法。需处理泛型参数
10801084
tryBuildArgsOfMethod(this, 2, clz, clzEggg.getCreator().getParamEgggAry(), (args2) -> {
1081-
tryBuildBeanOfClass3(clz, builder, anno, clzEggg.getCreator(), args2);
1085+
tryBuildBeanOfClass3(clz, builder, anno, (Constructor) clzEggg.getCreator().getConstr(), args2);
10821086
});
10831087
}
10841088
}
10851089

1086-
1087-
private void tryBuildBeanOfClass3(Class<?> clz, BeanBuilder builder, Annotation anno, ConstrEggg rawCon, Object[] rawConArgs) throws Throwable {
1090+
private void tryBuildBeanOfClass3(Class<?> clz, BeanBuilder builder, Annotation anno, Constructor rawCon, Object[] rawConArgs) throws Throwable {
10881091
//包装
1089-
BeanWrap bw = new BeanWrap(this, clz, (rawCon == null ? null : (Constructor) rawCon.getConstr()), rawConArgs);
1092+
BeanWrap bw = new BeanWrap(this, clz, rawCon, rawConArgs);
10901093
//执行构建
10911094
builder.doBuild(clz, bw, anno);
10921095
//尝试入库
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package features.solon.bean;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.noear.solon.core.AppContext;
5+
import org.noear.solon.core.BeanWrap;
6+
7+
/**
8+
*
9+
* @author noear 2025/11/8 created
10+
*
11+
*/
12+
public class BeanTest {
13+
@Test
14+
public void case1() {
15+
AppContext appContext = new AppContext();
16+
17+
appContext.beanScan(BeanTest.class);
18+
appContext.start();
19+
20+
BeanWrap bw = appContext.getWrap(InterfaceBean.class);
21+
22+
assert bw == null;
23+
}
24+
25+
@Test
26+
public void case2() {
27+
AppContext appContext = new AppContext();
28+
29+
appContext.beanMake(InterfaceBean.class);
30+
appContext.start();
31+
32+
BeanWrap bw = appContext.getWrap(InterfaceBean.class);
33+
34+
assert bw == null;
35+
}
36+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package features.solon.bean;
2+
3+
import org.noear.solon.annotation.Component;
4+
5+
/**
6+
*
7+
* @author noear 2025/11/8 created
8+
*
9+
*/
10+
@Component
11+
public interface InterfaceBean {
12+
}

0 commit comments

Comments
 (0)