修改配置类

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

@ -0,0 +1,19 @@
package org.pqh.core.annotation;
import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;
/**
* Created by reborn on 2017/9/20.
*/
public class ConfigurationSelector implements ImportSelector{
@Override
public String[] selectImports(AnnotationMetadata annotationMetadata) {
String path=this.getClass().getResource("").getPath();
if(path.contains("core")){
return new String[]{EnableWebCrawlerConfiguration.class.getName()};
}else{
return new String[0];
}
}
}

@ -2,6 +2,7 @@ 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.Configuration;
import org.springframework.context.annotation.Import;
import java.lang.annotation.*; import java.lang.annotation.*;
@ -13,5 +14,6 @@ import java.lang.annotation.*;
@Documented @Documented
@Configuration @Configuration
@ComponentScan("org.pqh.core") @ComponentScan("org.pqh.core")
@Import(ConfigurationSelector.class)
public @interface EnableWebCrawlerConfiguration { public @interface EnableWebCrawlerConfiguration {
} }

@ -1,5 +1,6 @@
package org.pqh.config; package org.pqh.config;
import org.pqh.core.annotation.ConfigurationSelector;
import org.pqh.core.config.HibernateConfig; 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;
@ -14,7 +15,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,WebCrawlerConfig.class}) @Import({HibernateConfig.class, ConfigurationSelector.class})
public class SpringConfig extends WebMvcConfigurerAdapter{ public class SpringConfig extends WebMvcConfigurerAdapter{
@Override @Override

@ -1,9 +1,8 @@
package org.pqh.config; package org.pqh.config;
import org.pqh.core.annotation.EnableWebCrawlerConfiguration; import org.pqh.core.annotation.EnableWebCrawlerConfiguration;
import org.springframework.context.annotation.Configuration;
@Configuration
@EnableWebCrawlerConfiguration @EnableWebCrawlerConfiguration
public class WebCrawlerConfig { public class WebCrawlerConfig {
} }

Loading…
Cancel
Save