修改配置类

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; 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.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata; import org.springframework.core.type.AnnotationMetadata;
/** /**
* Created by reborn on 2017/9/20. * Created by reborn on 2017/9/20.
*/ */
public class ConfigurationSelector implements ImportSelector{ public class ConfigurationSelector implements ImportSelector,LogManger{
@Override @Override
public String[] selectImports(AnnotationMetadata annotationMetadata) { public String[] selectImports(AnnotationMetadata annotationMetadata) {
String path=this.getClass().getResource("").getPath(); String appPath=this.getClass().getResource("").getPath();
if(path.contains("core")){ log.info("appPath="+appPath);
return new String[]{EnableWebCrawlerConfiguration.class.getName()}; //根据配置类判断
}else{ 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]; return new String[0];
} }
} }

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

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

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

Loading…
Cancel
Save