You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.5 KiB
40 lines
1.5 KiB
package org.pqh.core.annotation;
|
|
|
|
import org.pqh.core.util.LogManger;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.context.annotation.ImportSelector;
|
|
import org.springframework.core.type.AnnotationMetadata;
|
|
|
|
/**
|
|
* Created by reborn on 2017/9/20.
|
|
* 按条件导入配置类
|
|
*/
|
|
public class ConfigurationSelector implements ImportSelector,LogManger{
|
|
@Override
|
|
public String[] selectImports(AnnotationMetadata annotationMetadata) {
|
|
String appPath=this.getClass().getResource("").getPath();
|
|
log.info("appPath="+appPath);
|
|
//根据配置类判断
|
|
if(annotationMetadata.getClassName().equals("org.pqh.config.SpringConfig")){
|
|
return new String[]{"org.pqh.config.WebCrawlerConfig"};
|
|
}//根据配置类已有注解判断
|
|
else if(annotationMetadata.getAnnotationTypes().contains(Configuration.class.getName())){
|
|
return new String[]{"org.pqh.aaaaaaaaaaaa"};
|
|
}
|
|
//根据配置类路径判断
|
|
else if(appPath!=null&&appPath.contains("/web/WEB-INF")){
|
|
return new String[]{"org.pqh.bbbbbbbbbb"};
|
|
}
|
|
//根据系统信息
|
|
else if("XXXX".equals(System.getProperty("XXXX"))){
|
|
return new String[]{"org.pqh.cccccccccc"};
|
|
}
|
|
//根据环境变量
|
|
else if("XXX".equals(System.getenv("XXXX"))){
|
|
return new String[]{"org.pqh.ddddddddddd"};
|
|
}
|
|
else{
|
|
return new String[0];
|
|
}
|
|
}
|
|
}
|
|
|