0
java.net.BindException이 발생합니다. 나는 모든 bean을 autowire하기 위해 Spring을 사용하고 있으므로 같은 프로세스의 두 쓰레드가 실행되고 있다고 생각하지 않는다. 또한 모든 프로세스에 다른 포트를 사용합니다.Spring의 java.net.BindException
이 오류의 가능한 원인은 무엇입니까? 원인을 확인할 수있는 방법이 있습니까?
11:13:48,350 WARN [pool-2-thread-3] Service:215 - Thread exiting main loop due to exception:
java.lang.RuntimeException: java.net.BindException: Address already in use: JVM_Bind
at ca.uhn.hl7v2.app.AcceptorThread.afterStartup(AcceptorThread.java:106)
at ca.uhn.hl7v2.concurrent.Service.run(Service.java:202)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.net.BindException: Address already in use: JVM_Bind
at java.net.DualStackPlainSocketImpl.bind0(Native Method)
at java.net.DualStackPlainSocketImpl.socketBind(Unknown Source)
at java.net.AbstractPlainSocketImpl.bind(Unknown Source)
at java.net.PlainSocketImpl.bind(Unknown Source)
at java.net.ServerSocket.bind(Unknown Source)
at java.net.ServerSocket.bind(Unknown Source)
at ca.uhn.hl7v2.app.AcceptorThread.afterStartup(AcceptorThread.java:103)
편집 : 오류의 원인이 있습니다. 나는 ApplicationListener<ContextRefreshedEvent>
을 구현하는 스프링 @Component
을 사용하고 있습니다. 이 구성 요소는 Tomcat 시작시 실행되지만 유닛 테스트를 실행하면 Component가 다시 실행됩니다. 왜 그런 일이 일어나는거야?
@Component
public class RunBackgroundServices implements ApplicationListener<ContextRefreshedEvent> {
private final BackgroundServices backgroundServices;
private ExecutorService executor;
@Autowired
public RunBackgroundServices(BackgroundServices backgroundServices) {
this.backgroundServices= backgroundServices;
}
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
executor = Executors.newSingleThreadExecutor();
executor.submit(backgroundServices);
}
public void onApplicationEvent(ContextStoppedEvent event) {
executor.shutdown();
}
}
문제가 해결되면 문제가 해결 된 것으로 표시됩니다. – paul