init()
, 할당해제되는 1회에만 destroy()
됨.service()
메소드를 호출service()
메소드에 있는 doGet()
, doPost()
메소드로 동작// web
implementation "org.springframework.boot:spring-boot-starter-web"
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<!-- Servlet 등록 -->
<servlet>
<servlet-name>test</servlet-name>
<servlet-class>com.devcourse.springorder.servlet.TestServlet</servlet-class>
</servlet>
<!-- 서블릿과 url 패턴 매칭 -->
<servlet-mapping>
<servlet-name>test</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
@WebService
어노테이션 방법// loadOnStartup : 서블릿 init이 요청때 수행되는가 미리 수행되는가
// -1 : default (요청때 생성), 1 : (어플리케이션 시작 시 생성)
@WebServlet(value = "/*", loadOnStartup = 1)
public class TestServlet extends HttpServlet {
public class SpringOrderApplicationInitializer implements WebApplicationInitializer {
private static final Logger logger = LoggerFactory.getLogger(TestServlet.class);
// 이 메소드를 통해서 WAS에 서블릿 콘텍스트가 생성되고, 서블릿을 시작할 수 있음
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
logger.info("Starting Server...");
ServletRegistration.Dynamic servletRegistration = servletContext.addServlet("test", new TestServlet());
servletRegistration.addMapping("/*");
servletRegistration.setLoadOnStartup(1);
}
}