Skip to content

Commit

Permalink
Use beanclassloader load parse reference (#1163)
Browse files Browse the repository at this point in the history
* use bean classloader or tccl when parse reference interface

* use tccl parse interface type

---------

Co-authored-by: 致节 <hzj266771@antgroup.com>
  • Loading branch information
HzjNeverStop and 致节 authored Apr 18, 2023
1 parent 3310377 commit e38dcbf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ public void setApplicationContext(ApplicationContext applicationContext) throws
public Class<?> getInterfaceClass() {
if (interfaceClass == null) {
try {
interfaceClass = this.getClass().getClassLoader().loadClass(interfaceType);
interfaceClass = Thread.currentThread().getContextClassLoader()
.loadClass(interfaceType);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
} catch (NullPointerException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,8 @@ protected void doParseInternal(Element element, ParserContext parserContext,
}

String interfaceType = element.getAttribute(INTERFACE_ELEMENT);
Class<?> interfaceClass;
try {
interfaceClass = this.getClass().getClassLoader().loadClass(interfaceType);
} catch (Throwable t) {
throw new IllegalArgumentException("Failed to load class for interface: "
+ interfaceType, t);
}
builder.getBeanDefinition().setAttribute(FactoryBean.OBJECT_TYPE_ATTRIBUTE, interfaceClass);
builder.getBeanDefinition().setAttribute(FactoryBean.OBJECT_TYPE_ATTRIBUTE,
getInterfaceClass(interfaceType));
}

@Override
Expand All @@ -86,4 +80,13 @@ protected Class getBeanClass(Element element) {
public String supportTagName() {
return "reference";
}

protected Class getInterfaceClass(String interfaceType) {
try {
return Thread.currentThread().getContextClassLoader().loadClass(interfaceType);
} catch (Throwable t) {
throw new IllegalArgumentException("Failed to load class for interface: "
+ interfaceType, t);
}
}
}

0 comments on commit e38dcbf

Please sign in to comment.