package
com.springexamples;
import
java.io.IOException;
import
javax.servlet.ServletException;
import
javax.servlet.annotation.WebServlet;
import
javax.servlet.http.HttpServlet;
import
javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse;
import
org.springframework.web.context.support.XmlWebApplicationContext;
@WebServlet
(
"/MyBeanReader"
)
public
class
MyBeanReader
extends
HttpServlet {
public
void
doGet(HttpServletRequest request, HttpServletResponse response)
throws
ServletException, IOException {
XmlWebApplicationContext context =
new
XmlWebApplicationContext();
context.setConfigLocation(
"/WEB-INF/beans.xml"
);
context.setServletContext(request.getServletContext());
context.refresh();
SayHello hello = (SayHello) context.getBean(
"hello"
);
hello.sayGoodMorning();
hello.sayGoodEvening();
hello.sayGoodNight();
}
}