plugins {
id 'java'
id 'eclipse-wtp'
id 'war'
// war 가 없으면 배포가 안되고 배치도 안된다.
}
repositories {
jcenter()
}
dependencies {
// compileOnly?
// - 프로그래밍 하는 동안에만 사용하고 배치할 때는 제외하는 라이브러리를 가리킨다.
// - 프로그램이 배치되는 런타입 서버(예: 실행 중인 톰캣 서버)에서
// 라이브러리를 제공하는 경우 이 옵션으로 프로젝트에 추가한다.
// => Servlet API 라이브러리
//compileOnly group: 'javax.servlet', name: 'javax.servlet-api', version: '4.0.1'
// providedCompile?
// - compileOnly 처럼 컴파일 할 때만 사용한다.
// - 배포 파일에는 포함하지 않는다.
// - 단 이 옵션은 'war' 플러그인 사용시에만 사용할 수 있다.
providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version: '4.0.1'
// implementation?
// - 컴파일 할 때 사용한다.
// - 배포 파일에도 포함된다.
// => JSTL 명세를 구현한 라이브러리
implementation group: 'javax.servlet', name: 'jstl', version: '1.2'
implementation 'com.google.guava:guava:28.2-jre'
// testImplementation?
// - 단위 테스트를 수행할 때만 사용한다. 배치에 포함되지 않는다.
testImplementation 'junit:junit:4.12'
}
plugins {
id 'java'
id 'eclipse-wtp'
id 'war'
}
repositories {
jcenter()
}
dependencies {
providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version: '4.0.1'
implementation group: 'javax.servlet', name: 'jstl', version: '1.2'
// log4j 2.x 라이브러리
implementation 'org.apache.logging.log4j:log4j-core:2.14.0'
// Spring WebMVC 프레임워크 라이브러리
implementation 'org.springframework:spring-webmvc:5.3.2'
implementation 'com.google.guava:guava:28.2-jre'
testImplementation 'junit:junit:4.12'
}
<web-app>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/app-context.xml</param-value>
</context-param>
<servlet>
<servlet-name>app</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>app</servlet-name>
<url-pattern>/app/*</url-pattern>
</servlet-mapping>
</web-app>
public class MyWebApplicationInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) {
// Load Spring web application configuration
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.register(AppConfig.class);
// Create and register the DispatcherServlet
DispatcherServlet servlet = new DispatcherServlet(context);
ServletRegistration.Dynamic registration = servletContext.addServlet("app", servlet);
registration.setLoadOnStartup(1);
registration.addMapping("/app/*");
}
}