본문 바로가기

트러블슈팅

로컬에 서버 여러 대 실행 시킬 때, BeanCreationException: Error creating bean with name 'h2TCPServer', Exception opening port "9092" (port may be in use) 에러.

문제

로컬에서 서버 여러 대 띄울 때, 아래와 같이 h2TCPServer 관련 에러가 발생했다.

 

에러 문구를 자세히 보면 h2TCPServer 생성 시 사용할 9092 포트를 이미 사용하고 있다고 한다.

org.springframework.beans.factory.BeanCreationException: 
	Error creating bean with name 'h2TCPServer' defined in class path resource 
    	[com/.../config/DatabaseConfiguration.class]:Invocation of init method failed; 
    		 nested exception is org.h2.jdbc.JdbcSQLException: Exception opening port "9092" (port may be in use),
             cause: "java.net.BindException: Address already in use (Bind failed)" [90061-197]

 

원인

각 서버에서 자신의 h2 DB 서버를 실행시키는데, 모든 h2 DB 서버가 기본으로 9092 포트를 가진다.

해결

H2ConfigurationHelper.createServer에 다른 Port 번호를 넘겨줌으로써 해결했다.