source

스프링 부트:내장된 Tomcat 서블릿 컨테이너를 시작할 수 없습니다.

goodcode 2023. 3. 27. 22:45
반응형

스프링 부트:내장된 Tomcat 서블릿 컨테이너를 시작할 수 없습니다.

Spring Boot에 처음 접속하여 어플리케이션 실행 중 오류가 발생하였습니다.저는 튜토리얼을 따르고 있으며 POM에 대한 올바른 부모와 의존관계를 가지고 있다고 생각합니다.도와주세요.

메인 클래스:

package com.boot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * Hello world!
 *
 */

@SpringBootApplication
public class App 
{
    public static void main( String[] args )
    {
        SpringApplication.run(App.class, "hello");
    }
}

오류:

   org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat servlet container
        at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.start(TomcatEmbeddedServletContainer.java:165) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.startEmbeddedServletContainer(EmbeddedWebApplicationContext.java:293) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:141) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:764) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
        at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:357) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:305) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1124) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1113) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
        at com.boot.App.main(App.java:18) [classes/:na]Caused by: java.lang.IllegalStateException: Tomcat connector in failed state
        at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.start(TomcatEmbeddedServletContainer.java:159) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
        ... 10 common frames omitted

POM :

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>

  <groupId>com.boot</groupId>
  <artifactId>das-boot</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.1.RELEASE</version>
    </parent>
  <name>das-boot</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
  <dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
  </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

.application.yaml (오류)application.properties 다른 것으로 변경합니다.)른른하다

pom에 Tomcat 종속성을 추가해야 합니다.

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>

Linux 환경에서 실행 중인 경우 기본적으로 앱에는 기본 포트에 대한 권한이 없습니다.

VM에 대해 다음 옵션을 지정하여 8181을 사용해 보십시오.

-Dserver.port=8181

내 경우 첫 번째 오류는 " , Unable to start embedded Tomcat servlet container"입니다.첫 번째 문제를 여러 번 해결하려고 했지만, 진짜 문제는 나머지 문제였습니다.로거가 2종류의 Import가 있었기 때문에 초기화를 시도했을 때 컴파일 문제는 없었지만 런타임 에러였습니다.

제 조언은 모든 오류를 체크해보세요.처음 생각했던 문제가 아닐 수도 있습니다.따라서 이 문제에 대한 해결책은 다음에 표시되는 오류에 있을 수 있습니다.

이 에러만 있는 경우는, 상기의 몇개의 회답에 대응하고 있을 가능성이 있습니다.

"Unable to start to started Tomcat servlet container"라는 예외가 발생했을 때,

spring boot를 를 했습니다.debug=true application.properties,

다시 하면 '다니다'라는 메시지가 .java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String

따라서 아마도 낮은 버전의 servlet API를 사용하고 있으며, 스프링 부트 버전과 경합하고 있는 것을 알 수 있습니다.

pom.xml에 접속했는데, 의존관계 중 하나가 servlet 2.5를 사용하고 있어 제외했습니다.

이제 됐다.도움이 됐으면 좋겠다.

그냥 를 -X로 요.mvn로그를 . 파일을찾는 했습니다. 디버깅 로그를 확인합니다. .properties 파일을 찾는 동안 Spring에 문제가 발생했습니다.

이 문제는 프로젝트의 Java 버전이 변경되었기 때문에 발생할 수 있습니다.예를 들어 프로젝트가 Java 8에서 빌드되고 Java 버전을 11로 변경하면 이러한 문제가 발생할 수 있습니다.intellij 아이디어에서 [파일]-> [프로젝트 구조]로 이동하여 [프로젝트 SDK 버전]를 변경합니다.

Tomcat 의존관계 및 확장 SpringBootServlet에서 응용 프로그램클래스를 확장해야 합니다.이니셜라이저

@SpringBootApplication  
public class App extend SpringBootServletInitializer
{
    public static void main( String[] args )
    {
        SpringApplication.run(App.class, "hello");
    }
}

이 문제를 해결하는 간단한 방법은 다음과 같이 application.properties 또는 .yml 파일에 포함시키는 것입니다.server.port=0application.properties 및server.port: 0application.yml 파일의 경우.물론 사용 중인 스프링 부트 버전에 따라 이러한 버전이 변경될 수 있습니다.이것에 의해, 사용 가능한 빈 포토를 머신에 동적으로 할당할 수 있습니다.포트를 스태틱하게 할당하려면 위의 내용을server.port = someportnumberunix 기반의 OS 를 실행하고 있는 경우는, 문제의 포토로 좀비 액티비티를 체크해, 가능한 경우는, 다음의 방법으로 종료할 수 있습니다.fuser -k {theport}/tcp.yml 또는 .properties는 다음과 같습니다. server: port: 8089 servlet: context-path: /somecontextpath

저는 XML 이행에 문제가 있었습니다.모든 테이블과 시퀀스를 삭제하여 다음 bootRun에서 동작합니다.

위에서 설명한 바와 같이 Linux에서 실행 중인 경우 앱은 80 포트에 액세스할 수 없습니다.이 문제를 해결하려면 다음 두 가지 방법이 있습니다.

  1. root previlegies를 사용하여 응용 프로그램을 실행합니다.실가동용이 아닌 로컬 테스트용으로만 사용하는 것이 좋습니다.

  2. 예를 들어 포트 8081에서 앱을 실행하고 nginx를 사용하여 역프록시를 설정하고 요청을 80에서 8081로 리디렉션합니다.

언급URL : https://stackoverflow.com/questions/43579432/spring-boot-unable-to-start-embedded-tomcat-servlet-container

반응형