Process finished with exit code 1

경찬·2024년 9월 27일
0

트러블슈팅

목록 보기
1/2

문제 발생

분명 어제까지만 해도 잘 동작되던 서버가 오늘 강제종료가 되었다.

Process finished with exit code 1

일반적으로 애플리케이션이 정상적으로 종료되지 않고 외부 or 내부적인 요인에 의해 종료된 경우를 뜻하는 메세지이다.

1. 콘솔 로그 확인


우선 로그를 확인해봤을 때는 아무 문제도 없었다.

14:04:44,124 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - Processing appender named [console]
14:04:44,125 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
14:04:44,128 |-INFO in ch.qos.logback.core.model.processor.ImplicitModelHandler - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
14:04:44,147 |-WARN in ch.qos.logback.core.model.processor.AppenderModelHandler - Appender named [console-infolog] not referenced. Skipping further processing.
14:04:44,147 |-INFO in ch.qos.logback.classic.model.processor.LoggerModelHandler - Setting level of logger [com.example.demo] to DEBUG
14:04:44,147 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@b70da4c - Propagating DEBUG level on Logger[com.example.demo] onto the JUL framework
14:04:44,148 |-INFO in ch.qos.logback.classic.model.processor.LoggerModelHandler - Setting level of logger [jdbc.sqlonly] to INFO
14:04:44,148 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@b70da4c - Propagating INFO level on Logger[jdbc.sqlonly] onto the JUL framework
14:04:44,148 |-INFO in ch.qos.logback.classic.model.processor.LoggerModelHandler - Setting level of logger [jdbc.resultsettable] to INFO
14:04:44,148 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@b70da4c - Propagating INFO level on Logger[jdbc.resultsettable] onto the JUL framework
14:04:44,148 |-INFO in ch.qos.logback.classic.model.processor.RootLoggerModelHandler - Setting level of ROOT logger to OFF
14:04:44,148 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@b70da4c - Propagating OFF level on Logger[ROOT] onto the JUL framework
14:04:44,148 |-INFO in ch.qos.logback.core.model.processor.AppenderRefModelHandler - Attaching appender named [console] to Logger[ROOT]
14:04:44,148 |-INFO in ch.qos.logback.core.model.processor.DefaultProcessor@1c3146bc - End of configuration.
14:04:44,148 |-INFO in org.springframework.boot.logging.logback.SpringBootJoranConfigurator@47a86fbb - Registering current configuration as safe fallback point

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/

 :: Spring Boot ::                (v3.3.3)

2024-09-27 14:04:44,211  INFO [com.example.demo.DemoApplication] Starting DemoApplication using Java 17.0.10 with PID 28948 
2024-09-27 14:04:44,212 DEBUG [com.example.demo.DemoApplication] Running with Spring Boot v3.3.3, Spring v6.1.12
2024-09-27 14:04:44,212  INFO [com.example.demo.DemoApplication] No active profile set, falling back to 1 default profile: "default"
2024-09-27 14:04:45,584  INFO [jdbc.sqlonly] SELECT NOW() FROM dual

Process finished with exit code 1

2. SQL 서버 확인


“설마 application.properties 파일 설정 문제인가?”

spring.application.name=demo
spring.datasource.hikari.driver-class-name=net.sf.log4jdbc.sql.jdbcapi.DriverSpy
spring.datasource.hikari.jdbc-url=jdbc:log4jdbc:mariadb://localhost:3306/spring_demo?serverTimezone=Asia/Seoul&useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true
spring.datasource.hikari.username=
spring.datasource.hikari.password=
spring.datasource.hikari.connection-test-query=SELECT NOW() FROM dual

설정 파일에는 아무 문제가 없었고, SQL 서버를 확인해봤는데 역시 잘 동작함.

3. try-catch로 서버 문제 확인하기


그러면 메인서버의 문제겠거니 하고 메인 서버를 열어주는 코드로 이동하여 아래와 같이 수정했다.

수정전

@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
         SpringApplication.run(DemoApplication.class, args);
    }
}

수정후

@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        try {
            SpringApplication.run(DemoApplication.class, args);
        } catch (Exception e) {
            System.err.println("An error occurred while starting the application:");
            e.printStackTrace();
            System.exit(1);
        }
    }

}

에러발생

An error occurred while starting the application:
org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'
	at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:288)
	at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:469)
	at java.base/java.lang.Iterable.forEach(Iterable.java:75)
	at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:257)
	at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:202)
	at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:990)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:628)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:335)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1363)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1352)
	at com.example.demo.DemoApplication.main(DemoApplication.java:11)
Caused by: org.springframework.boot.web.server.PortInUseException: Port 8080 is already in use
	at org.springframework.boot.web.server.PortInUseException.lambda$throwIfPortBindingException$0(PortInUseException.java:70)
	at org.springframework.boot.web.server.PortInUseException.lambda$ifPortBindingException$1(PortInUseException.java:85)
	at org.springframework.boot.web.server.PortInUseException.ifCausedBy(PortInUseException.java:103)
	at org.springframework.boot.web.server.PortInUseException.ifPortBindingException(PortInUseException.java:82)
	at org.springframework.boot.web.server.PortInUseException.throwIfPortBindingException(PortInUseException.java:69)
	at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:250)
	at org.springframework.boot.web.servlet.context.WebServerStartStopLifecycle.start(WebServerStartStopLifecycle.java:44)
	at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:285)
	... 13 more
Caused by: java.lang.IllegalArgumentException: standardService.connector.startFailed
	at org.apache.catalina.core.StandardService.addConnector(StandardService.java:222)
	at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.addPreviouslyRemovedConnectors(TomcatWebServer.java:310)
	at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:236)
	... 15 more
Caused by: org.apache.catalina.LifecycleException: Protocol handler start failed
	at org.apache.catalina.connector.Connector.startInternal(Connector.java:1061)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:164)
	at org.apache.catalina.core.StandardService.addConnector(StandardService.java:219)
	... 17 more
Caused by: java.net.BindException: Address already in use: bind
	at java.base/sun.nio.ch.Net.bind0(Native Method)
	at java.base/sun.nio.ch.Net.bind(Net.java:555)
	at java.base/sun.nio.ch.ServerSocketChannelImpl.netBind(ServerSocketChannelImpl.java:337)
	at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:294)
	at org.apache.tomcat.util.net.NioEndpoint.initServerSocket(NioEndpoint.java:239)
	at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:194)
	at org.apache.tomcat.util.net.AbstractEndpoint.bindWithCleanup(AbstractEndpoint.java:1304)
	at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:1390)
	at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:643)
	at org.apache.catalina.connector.Connector.startInternal(Connector.java:1058)
	... 19 more

웹서버 구동을 하는데에 있어 문제가 있나보다.

에러 로그를 쭉 확인해봤다.

음…8080 포트를 ‘어디선가’ 사용중이라 PortInUseException이 발생했군.

포트쪽 문제였다.

그럼 해결방안은 아래와 같다.

1. 사용 중인 포트 확인하여 종료하기
2. 포트를 변경하기

1. (윈도우11)CMD를 사용하여 사용 중인 포트 확인하여 종료하기


윈도우 11을 사용중이라 cmd를 열어 8080포트를 사용하는 PID를 확인해보았다.

netstat -a -o 입력

기다리다 보면 포트를 사용중인 프로세스들이 조회가 될 것이다…

8080포트가 안보이는군…

그러면 임의로 8251 포트를 죽여보자… 해당 포트의 PID번호는… 13656이다.

Ctrl+C로 진행중인 프로세스를 종료하고

taskkill /f /pid 13656을 입력하자.

포트번호 8251을 입력하면 실패하고, PID 번호 13656을 입력하자 성공적으로 된 안내문이 뜬다.

2. 포트를 변경하기


spring.application.name=demo
spring.datasource.hikari.driver-class-name=net.sf.log4jdbc.sql.jdbcapi.DriverSpy
spring.datasource.hikari.jdbc-url=jdbc:log4jdbc:mariadb://localhost:3306/spring_demo?serverTimezone=Asia/Seoul&useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true
spring.datasource.hikari.username=
spring.datasource.hikari.password=
spring.datasource.hikari.connection-test-query=SELECT NOW() FROM dual
server.port=80

아무 문제 없이 구동됩니다 ㅎㅎ

3. 콘솔 로그에 출력된 PID번호로 포트 죽이기


8080포트로 서버를 구동했는데, PID 번호가 16212이다.

그럼 바로 8080 포트를 종료하고 다시 서버를 구동해보겠다.

netstat -ano | findstr :8080 를 입력하면 8080 포트와 관련된 프로세스들이 모두 조회되어야 정상인데, 아무것도 조회가 안된다.

결국은 포트를 바꾸어서 해결했다.

이유를 모르겠다… 아는 분 있으시면 알려주시면 감사하겠습니다 ㅠㅠ

참고자료


exit code 1 발생시 try-catch로 에러 잡아보기 : Process finished with exit code 1 Spring Boot Intellij
WebServerStartStop의 원인과 해결 방안 1번째: Failed to start bean 'webServerStartStop'; Unable to start embedded Tomcat server - spring-boot-starter-web
WebServerStartStop의 원인과 해결 방안 2번째:[EC2 / linux] springboot 배포 오류 : Failed to start bean 'webServerStartStop, java.net.SocketException: Permission denied
포트 종료 하는 방법: [개발 지식] PID 찾기, Window Port 종료 시키기(Port Kill)

profile
이것저것 작성합니다

0개의 댓글