Skip to content

Instantly share code, notes, and snippets.

@prashant4224
Created May 30, 2020 18:03
Show Gist options
  • Save prashant4224/335b4428c75ac6e05860219d572ccf65 to your computer and use it in GitHub Desktop.
Save prashant4224/335b4428c75ac6e05860219d572ccf65 to your computer and use it in GitHub Desktop.
import org.springframework.beans.factory.annotation.Lookup;
import org.springframework.stereotype.Component;
@Component
public class RequestManager{
private RequestHandler requestHandler;
public void handleRequest(){
requestHandler = getRequestHandler();
requestHandler.handleRequest();
}
@Lookup
public RequestHandler getRequestHandler() {
return null;
}
}
@Component
@Scope("prototype")
public class RequestHandler {
RequestHandler(){
System.out.println("In Request Handler Constructor");
}
public void handleRequest(){
System.out.println("Handling request");
}
}
public class App {
public static void main( String[] args ){
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext
("appcontext.xml");
RequestManager bean = (RequestManager) context.getBean("requestManager");
bean.handleRequest();
bean.handleRequest();
bean.handleRequest();
context.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment