[Tomcat] war 중복 배포 방지 (스케줄러 중복 실행 문제)

fever·2025년 8월 6일
0

문제

로컬에선 문제 없던 스케줄러가 톰캣에 올리면 중복 실행되는 문제 발생했다.
아래는 기존 server.xml 설정이다.

<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">  
<Context docBase="test" path="/" reloadable="true" />

원인

/webapps/
├── test.war
├── test/          ← test.war가 자동으로 풀리면서 생성됨
├── ROOT/          ← 기본 context

톰캣이 실행되면 webapps안에 test 폴더와 ROOT 폴더가 생기는데,
결과적으로 동일 WAR의 인스턴스가 중복 실행되어 @Scheduled 사용시 2번 실행된다.

해결 방법

1. autoDeploy, deployOnStartup비활성화

<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="false" deployOnStartup="false">  
<Context docBase="test" path="/" reloadable="true" />

autoDeploy="false"
→ WAR 파일이 있어도 자동 배포 안 함

deployOnStartup="false"
→ 톰캣 기동 시 WAR 자동 전개 안 함

<Context>에 명시된 docBase="test"만 명확하게 실행되며 test.war가 자동으로 풀려서 test/ 폴더 생기는 것도 방지된다.

2. appBase 자체를 별도로 설정

<Host name="localhost" appBase="webapps/test" unpackWARs="true" autoDeploy="true">  
<Context docBase="test" path="/" reloadable="true" />

webapps/test라는 별도의 디렉토리를 톰캣 배포 루트(appBase)로 지정하여 해당 경로에 test.war만 존재하도록 관리한다.

profile
선명한 삶을 살기 위하여

0개의 댓글