修改配置类

master
luffy9412 7 years ago
parent d1394a0962
commit 4027ff7b2a
  1. 30
      core/src/main/java/org/pqh/core/annotation/ConfigurationSelector.java
  2. 4
      core/src/main/java/org/pqh/core/annotation/EnableWebCrawlerConfiguration.java
  3. 3
      web/src/main/java/org/pqh/config/SpringConfig.java
  4. 1
      web/src/main/java/org/pqh/config/WebCrawlerConfig.java

@ -1,18 +1,38 @@
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{
public class ConfigurationSelector implements ImportSelector,LogManger{
@Override
public String[] selectImports(AnnotationMetadata annotationMetadata) {
String path=this.getClass().getResource("").getPath();
if(path.contains("core")){
return new String[]{EnableWebCrawlerConfiguration.class.getName()};
}else{
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];
}
}

@ -1,8 +1,6 @@
package org.pqh.core.annotation;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import java.lang.annotation.*;
@ -12,8 +10,6 @@ import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@Documented
@Configuration
@ComponentScan("org.pqh.core")
@Import(ConfigurationSelector.class)
public @interface EnableWebCrawlerConfiguration {
}

@ -1,7 +1,6 @@
package org.pqh.config;
import org.pqh.core.annotation.ConfigurationSelector;
import org.pqh.core.config.HibernateConfig;
import org.springframework.context.annotation.*;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
@ -15,7 +14,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
@EnableAspectJAutoProxy
@PropertySource("classpath:config.properties")
@ComponentScan({"${spring.scan:org.pqh.controller}"})
@Import({HibernateConfig.class, ConfigurationSelector.class})
@Import({ConfigurationSelector.class})
public class SpringConfig extends WebMvcConfigurerAdapter{
@Override

@ -2,7 +2,6 @@ package org.pqh.config;
import org.pqh.core.annotation.EnableWebCrawlerConfiguration;
@EnableWebCrawlerConfiguration
public class WebCrawlerConfig {
}

Loading…
Cancel
Save