Spring Boot App이 부팅 즉시 항상 종료되는 이유는 무엇입니까?
이것은 첫 번째 스프링 부트 코드입니다.불행히도, 그것은 항상 꺼집니다.웹 클라이언트가 브라우저에서 데이터를 가져올 수 있도록 지속적으로 실행되기를 기대했습니다.
package hello;
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;
@Controller
@EnableAutoConfiguration
public class SampleController {
@RequestMapping("/")
@ResponseBody
String home() {
return "Hello World!";
}
public static void main(String[] args) throws Exception {
SpringApplication.run(SampleController.class, args);
}
}
[@localhost initial]$ java -jar build/libs/gs-spring-boot-0.1.0.jar
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.0.0.RC4)
2014-03-13 09:20:24.805 INFO 14650 --- [ main] hello.SampleController : Starting SampleController on localhost.localdomain with PID 14650 (/home/xxx/dev/gs-spring-boot/initial/build/libs/gs-spring-boot-0.1.0.jar started by xxx)
2014-03-13 09:20:25.002 INFO 14650 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@b9eec: startup date [Thu Mar 13 09:20:24 EDT 2014]; root of context hierarchy
2014-03-13 09:20:28.833 INFO 14650 --- [ main] o.s.b.a.e.jmx.EndpointMBeanExporter : Registering beans for JMX exposure on startup
2014-03-13 09:20:30.148 INFO 14650 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 0
2014-03-13 09:20:30.154 INFO 14650 --- [ main] o.s.b.a.e.jmx.EndpointMBeanExporter : Located managed bean 'requestMappingEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=requestMappingEndpoint]
2014-03-13 09:20:30.316 INFO 14650 --- [ main] o.s.b.a.e.jmx.EndpointMBeanExporter : Located managed bean 'environmentEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=environmentEndpoint]
2014-03-13 09:20:30.335 INFO 14650 --- [ main] o.s.b.a.e.jmx.EndpointMBeanExporter : Located managed bean 'healthEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=healthEndpoint]
2014-03-13 09:20:30.351 INFO 14650 --- [ main] o.s.b.a.e.jmx.EndpointMBeanExporter : Located managed bean 'beansEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=beansEndpoint]
2014-03-13 09:20:30.376 INFO 14650 --- [ main] o.s.b.a.e.jmx.EndpointMBeanExporter : Located managed bean 'infoEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=infoEndpoint]
2014-03-13 09:20:30.400 INFO 14650 --- [ main] o.s.b.a.e.jmx.EndpointMBeanExporter : Located managed bean 'metricsEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=metricsEndpoint]
2014-03-13 09:20:30.413 INFO 14650 --- [ main] o.s.b.a.e.jmx.EndpointMBeanExporter : Located managed bean 'traceEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=traceEndpoint]
2014-03-13 09:20:30.428 INFO 14650 --- [ main] o.s.b.a.e.jmx.EndpointMBeanExporter : Located managed bean 'dumpEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=dumpEndpoint]
2014-03-13 09:20:30.450 INFO 14650 --- [ main] o.s.b.a.e.jmx.EndpointMBeanExporter : Located managed bean 'autoConfigurationAuditEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=autoConfigurationAuditEndpoint]
2014-03-13 09:20:30.465 INFO 14650 --- [ main] o.s.b.a.e.jmx.EndpointMBeanExporter : Located managed bean 'shutdownEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=shutdownEndpoint]
2014-03-13 09:20:30.548 INFO 14650 --- [ main] o.s.b.a.e.jmx.EndpointMBeanExporter : Located managed bean 'configurationPropertiesReportEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=configurationPropertiesReportEndpoint]
2014-03-13 09:20:30.589 INFO 14650 --- [ main] hello.SampleController : Started SampleController in 7.396 seconds (JVM running for 9.569)
2014-03-13 09:20:30.608 INFO 14650 --- [ Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@b9eec: startup date [Thu Mar 13 09:20:24 EDT 2014]; root of context hierarchy
2014-03-13 09:20:30.610 INFO 14650 --- [ Thread-2] o.s.c.support.DefaultLifecycleProcessor : Stopping beans in phase 0
2014-03-13 09:20:30.624 INFO 14650 --- [ Thread-2] o.s.b.a.e.jmx.EndpointMBeanExporter : Unregistering JMX-exposed beans on shutdown
조언 부탁드립니다.
고마워요.
추신, 빌드 그레이들 잘못이에요
dependencies {
// tag::jetty[]
compile("org.springframework.boot:spring-boot-starter-web") {
**exclude module: "spring-boot-starter-tomcat"**
}
위의 행을 굵은 글씨로 떼면 모든 것이 잘 된다.내 어플리케이션 콘텍스트는 이제 정확합니다.고마워요 데이브
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.0.0.RC4)
2014-03-13 13:58:08.965 INFO 7307 --- [ main] hello.Application : Starting
Application on with PID 7307 (/ladev/home/xxx/dev/gs-spring-boot/initial/build/libs/gs-spring-boo
t-0.1.0.jar started by xxx)
2014-03-13 13:58:09.021 INFO 7307 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshi
ng org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@45490eb5: startup
date [Thu Mar 13 13:58:09 MDT 2014]; root of context hierarchy
2014-03-13 13:58:09.653 INFO 7307 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overridi
ng bean definition for bean 'beanNameViewResolver': replacing [Root bean: class [null]; scope=; abstract=fal
se; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanNam
e=org.springframework.boot.actuate.autoconfigure.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration;
factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class
path resource [org/springframework/boot/actuate/autoconfigure/ErrorMvcAutoConfiguration$WhitelabelErrorView
Configuration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3;
dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconf
igure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter; factoryMethodName=beanNameViewResolver; in
itMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/au
toconfigure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]]
해결 방법: 앱은 클래스 경로에 내장 컨테이너(예: Tomcat)가 없으므로 웹 앱이 아닙니다.하나를 더하면 해결된다.Maven을 사용하고 있는 경우는, 이것을 에 추가합니다.pom.xml
:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Gradle의 경우(build.gradle
) ) 。
dependencies {
compile 'org.springframework.boot:spring-boot-starter-web'
}
저도 같은 문제가 있었는데 제거했을 때
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
다시 작동하기 시작했어
이 문제를 해결하는 방법은 다음과 같습니다.
pom.xml 파일의 spring-boot-starter-web에 의존하지 않는지 확인합니다.pom.xml 파일을 올바르게 가져오려면 이 링크 start.spring을 사용합니다.이오
위의 종속성이 있지만 여전히 문제가 있는 경우 내장된 Tomcat jar가 존재할 가능성이 높습니다.이를 확인하려면 디버깅모드에서 maven build를 실행합니다.
mvn spring-boot:run --debug
다음과 같은 메시지를 찾습니다.
[WARNING] error reading /Users/sparrowmac1/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/8.5.20/tomcat-embed-core-8.5.20.jar; invalid LOC header (bad signature) [WARNING] error reading /Users/sparrowmac1/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.8.10/jackson-core-2.8.10.jar; invalid LOC header (bad signature)
이러한 메시지가 표시될 경우 로컬 maven repo를 삭제하고 다시 시도하십시오.
mvn dependency:purge-local-repository
당신의 코드에 맞지 않을 수도 있지만, 다음과 같은 코드 조각이 있는지 알아냈습니다.
@SpringBootApplication
public class SpringBootApacheKafkaApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootApacheKafkaApplication.class,args).close();
}
}
close() 메서드를 삭제합니다.이제 내 문제가 해결됐어!내가 도와줄 수 있을 것 같아
어플리케이션은 Spring Boot Batch이며 application.properties의 다음 행에 코멘트를 하면 문제가 해결되었습니다.
spring.main.web-application-type=none
저의 경우 메서드의 반환값을 사용하지 않는 정적 분석 오류를 수정했을 때 문제가 발생하였습니다.
Application.java의 이전 작업 코드는 다음과 같습니다.
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
문제를 일으킨 새로운 코드는 다음과 같습니다.
public static void main(String[] args) {
try (ConfigurableApplicationContext context =
SpringApplication.run(Application.class, args)) {
LOG.trace("context: " + context);
}
}
resource block을 사용하여 시도하면 응용 프로그램 시작 후 컨텍스트가 닫히고 상태 0으로 응용 프로그램이 종료됩니다.이는 snarqube 정적 분석에 의해 보고된 리소스 누출 오류를 무시해야 하는 경우입니다.
gradle을 사용하여 종속성 블록 내의 build.gradle.kts 파일에서 이 행을 대체했습니다.
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
이와 함께.
compile("org.springframework.boot:spring-boot-starter-web")
정상적으로 동작합니다.
Starter-tomcat이 설정되지 않은 경우 IDE에서 실행 중인 경우 제공된 범위를 코멘트 오프해야 하는 이유는 무엇입니까?라는 답이 맞다고 생각합니다.명령을 실행하는 동안 스코프가 문제를 만들지 않습니다.왜 그랬을까?
어쨌든 제 생각을 좀 더 추가했습니다.
다른 가능성일 뿐이지
교체했습니다.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
와 함께
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
아무 문제 없이 시작했는데
인텔리에서 새로운 SPring 부트 프로젝트를 초기화했습니다.Spring Boot 개발 도구를 사용하는 JIdea는 pom.xml에서는 의존관계만 있었습니다.
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
...
또한 spring-boot-starter-web을 아티팩트화해야 합니다.이 의존관계를 pom.xml에 추가합니다.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
이 기능은 스프링 부트 2.0.0에서 작동합니다.
교체하다
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
와 함께
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>9.0.6</version>
</dependency>
제 경우, 이 문제를 다음과 같이 수정했습니다.-
를 했습니다.
C:\Users\myuserId\.m2\repository\org\apache
했습니다.
pom.xml
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
파일에 했습니다.
..\yourprojectfolder\src\main\resourcesand\application.properties
(수동으로 작성했습니다.)server.port=8099 spring.profiles.active=@spring.profiles.active@
그 때문에, 나는 나의 블록아래에 추가했다.
pom.xml
아래<build>
★★★★★★ 。<build> . . <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> . . </build>
의 마지막 ★★★★★★★★★★★★★★★★★.pom.xml
줄서기 모양
<?xml version="1.0" encoding="UTF-8"?>
<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.bhaiti</groupId>
<artifactId>spring-boot-rest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>spring-boot-rest</name>
<description>Welcome project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>
을 웹 않다면 Spring을 하세요.@EnableAsync
★★★★★★★★★★★★★★★★★」@EnableScheduling
@EnableAsync
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
나는 이곳저곳 답을 검토했지만 여전히 문제가 있었다.(op과 마찬가지로) Kubernetes에서 실행 중이었고 앱은 괜찮았지만 Kubernetes에는 문제가 있었습니다.
포트 환경 변수에 따라 앱이 시작되지 않았습니다.따라서 kubernetes/helm은 8443에서 실행하도록 지시하고 Live probe를 실행하도록 지시하고 있었습니다만, 이 명령어는 application.properties의 다른 포트(8123 등)에서 실행되고 있었습니다.
kubernetes 이벤트(get 이벤트)는 라이브네스 프로브가 실패했음을 나타냈기 때문에 kubernetes는 30초마다 포드/앱을 종료했습니다.
순환 스프링 주입 종속성이 있는 경우 로깅 수준 및 기타 몇 가지 요인에 따라 경고 없이 실패합니다.
클래스 A는 클래스 B를 주입하고 클래스 B는 클래스 A를 주입합니다.이 경우에는 컨스트럭터를 경유합니다.
저는 이런 문제가 있었습니다.저의 경우는 단순한 어설픈 실수로 인해 발생했습니다.우리 반에는 다음과 같은 문제가 있었습니다.
@SpringBootApplication
public class MyApplication implements ApplicationRunner {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
public void run(ApplicationArguments args) throws Exception {
}
}
"Implements Application Runner"와 실행 방법(복사 붙여넣기 오류로 인해 있음)을 삭제하고 실행했습니다.
Java 9 JPMS를 사용하는 경우, spring-boot-starter-web을 의존관계로 추가하는 것만으로는 충분하지 않습니다.tomcat-embed lib는 실행 시 사용할 수 없고 spring boot은 앱을 웹 앱으로 인식하지 않기 때문입니다.
이 문제를 해결하려면 메인 앱용 module-info.java에 추가된 다음 명령을 통해 Tomcat embedd를 사용할 수 있도록 합니다.
requires org.apache.tomcat.embed.core;
제 경우, 이미 'spring-boot-starter-web'에 의존하여 IDE 내에서 spring-boot 앱으로 실행하면 프로젝트는 정상적으로 시작되지만, K8에 전개하면 앱이 시작되고 즉시 자동 정지됩니다.Spring Boot Servlet을 확장하기 위해 메인 앱 클래스를 수정했습니다.이니셜라이저로 자동 정지가 해결된 것 같습니다.
@SpringBootApplication public class MyApp extends SpringBootServletInitializer { public static void main(String[] args) {
SpringApplication.run(MyApp.class, args); }}
저도 비슷한 문제가 있었어요.저는 다음과 같은 스타터 웹 패키지만 가지고 있지 않았습니다.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
하지만 그것은 충분하지 않다.다른 필수 종속성을 가져오려면 부모도 추가해야 합니다.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
Maven m2 폴더 삭제(Linux~/.m2) 및 애플리케이션 재구축
언급URL : https://stackoverflow.com/questions/22380119/why-does-my-spring-boot-app-always-shutdown-immediately-after-starting
'programing' 카테고리의 다른 글
vue js에 있는 구글 맵의 infow에서 @click inside를 사용하여 함수를 트리거하는 방법은 무엇입니까? (0) | 2022.07.03 |
---|---|
내부에 변이가 없는 Action vuex를 호출하는 것이 나쁜가요? (0) | 2022.07.03 |
Vue.js vuex에서의 실행 취소와 같은 상태로 되돌아가다 (0) | 2022.07.03 |
"unsigned long"을 C로 인쇄하는 방법 (0) | 2022.07.03 |
중첩된 vue-draggable 요소 (0) | 2022.07.03 |