Skip to content

Commit

Permalink
修复Spring AOP代理类无法找到Annitation和Interfaces的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
fanyi-zhao committed Feb 5, 2021
1 parent 6d6149b commit e6b7a92
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ doc/
target/
out/
.DS_Store
.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
package com.alibaba.cola.extension.register;

import com.alibaba.cola.extension.*;

import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.stereotype.Component;
import org.springframework.util.ClassUtils;

import javax.annotation.Resource;

Expand All @@ -27,22 +30,21 @@ public class ExtensionRegister{

public void doRegistration(ExtensionPointI extensionObject){
Class<?> extensionClz = extensionObject.getClass();
Extension extensionAnn = extensionClz.getDeclaredAnnotation(Extension.class);
Extension extensionAnn = AnnotationUtils.findAnnotation(extensionClz, Extension.class);
BizScenario bizScenario = BizScenario.valueOf(extensionAnn.bizId(), extensionAnn.useCase(), extensionAnn.scenario());
ExtensionCoordinate extensionCoordinate = new ExtensionCoordinate(calculateExtensionPoint(extensionClz), bizScenario.getUniqueIdentity());
ExtensionPointI preVal = extensionRepository.getExtensionRepo().put(extensionCoordinate, extensionObject);
if (preVal != null) {
throw new RuntimeException("Duplicate registration is not allowed for :" + extensionCoordinate);
}

}

/**
* @param targetClz
* @return
*/
private String calculateExtensionPoint(Class<?> targetClz) {
Class[] interfaces = targetClz.getInterfaces();
Class<?>[] interfaces = ClassUtils.getAllInterfacesForClass(targetClz);
if (interfaces == null || interfaces.length == 0)
throw new RuntimeException("Please assign a extension point interface for "+targetClz);
for (Class intf : interfaces) {
Expand Down
6 changes: 6 additions & 0 deletions cola-components/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.taobao</groupId>
<artifactId>parent</artifactId>
<version>2.0.0</version>
</parent>

<groupId>com.alibaba.cola</groupId>
<artifactId>cola-components-parent</artifactId>
<version>4.1.0-SNAPSHOT</version>
Expand Down

0 comments on commit e6b7a92

Please sign in to comment.