com.addplus.server.action.config.token.TokenAnnotationConfig Maven / Gradle / Ivy
The newest version!
package com.addplus.server.action.config.token;
import com.addplus.server.action.config.aspect.NotToken;
import com.addplus.server.core.utils.PackageUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@Configuration
public class TokenAnnotationConfig {
@Value("${action.token.package:com.addplus.server.web.serviceimpl}")
private String packageName;
@Bean(name = "tokenAnnontationMap")
public Map getTokenAnnontation() {
Map map = new HashMap<>();
// 获取所有service
Set> allClasses = new HashSet>();
for (String tmp : packageName.split(",")) {
Set> classes = PackageUtil.getClasses(tmp);
allClasses.addAll(classes);
}
for (Class tmp : allClasses) {
Method[] methods = tmp.getMethods();
for (Method method : methods) {
Annotation[] annotations = method.getAnnotations();
if (annotations.length>0){
for (Annotation a:annotations) {
if (a.annotationType().equals(NotToken.class)){
map.put(tmp.getInterfaces()[0].getName()+ "_" + method.getName(), true);
break;
}
}
}
}
}
return map;
}
}