Package com.jcasey

Source Code of com.jcasey.SpiderController

package com.jcasey;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan
public class SpiderController {

  @Bean
  public Spider getSpider()
  {
    return new Spider(getHttpClient(), getHttpParser());
  }
 
  @Bean
  public HttpClient getHttpClient()
  {
    return new HttpClientImpl();
  }
 
  @Bean
  public HttpParser getHttpParser()
  {
    return new HttpParserImpl();
  }
 
  public static void main(String[] args)
  {
    // bootstrap spring by scanning for components linked to the SpiderController
    ApplicationContext ctx = new AnnotationConfigApplicationContext(SpiderController.class);

    // use our context to get access to the Spider component
    Spider webCrawler = (Spider) ctx.getBean(Spider.class);
   
    // the Spider components @Autowire annotation will automatically load the HttpClient and HttpParser @Components.
    webCrawler.startCrawl();
  }
}
TOP

Related Classes of com.jcasey.SpiderController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.