【问题标题】:IntelliJ Process finished with exit code 0 when spring-boot run当 spring-boot 运行时 IntelliJ 进程以退出代码 0 完成
【发布时间】:2015-12-21 22:01:27
【问题描述】:

从 IntelliJ-Idea 启动 spring-boot 应用程序时遇到问题。通过终端运行应用程序时我没有这个问题。

:: Spring Boot ::        (v1.2.1.RELEASE)

2015-09-24 12:22:44.274  WARN 22380 --- [           main] n.sf.ehcache.config.CacheConfiguration   : Cache 'publicationsCount' is set to eternal but also has TTI/TTL set.  To avoid this warning, clean up the config removing conflicting values of eternal, TTI and TTL. Effective configuration for Cache 'publicationsCount' will be eternal='true', timeToIdleSeconds='0', timeToLiveSeconds='0'.

Process finished with exit code 0

我认为这个警告不会导致它。可能是什么原因?

【问题讨论】:

  • 退出代码 0 表示,应用程序没有错误地结束。那么问题出在哪里?
  • 但它不应该关闭。 Spring-boot 应该等待运行,等待请求。
  • 仅当您在应用程序中包含了一个您未指定的 Web 服务器时。所以如果您需要更多帮助,您应该发布相关配置。
  • 一个愚蠢的原因可能是SpringApplication.run()中的错误类

标签: java spring intellij-idea spring-boot


【解决方案1】:

删除 provided 范围的 spring-boot-starter-tomcat 依赖对我有帮助。

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

【讨论】:

  • 谢谢,我删除了我的 gradle 等效项:providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
  • 这行得通。但是你能告诉我为什么这会奏效吗?是不是因为“提供”意味着它只在编译期间可用?。
【解决方案2】:

我从https://start.spring.io/ (sprint initializr) 创建了一个简单的项目,并添加了一个简单的控制器来运行应用程序。

@RestController
public class testController {

    @GetMapping(value="/")
    //@RequestMapping(value="/",method=RequestMethod.GET)
    public String hello(){
        return "Hello World!!";
    }
}

但它没有开始,因为我的 pom 没有

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

添加后我的应用程序开始了......

2019-11-05 14:33:32.302  INFO 39079 --- [           main] o.s.s.web.DefaultSecurityFilterChain     : Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@dd20ebc, org.springframework.security.web.context.SecurityContextPersistenceFilter@57b1ec84, org.springframework.security.web.header.HeaderWriterFilter@2c2a7d53, org.springframework.security.web.csrf.CsrfFilter@b9b97ad, org.springframework.security.web.authentication.logout.LogoutFilter@29f3185c, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@4ffa7041, org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter@2c2a903f, org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter@6c70b7c3, org.springframework.security.web.authentication.www.BasicAuthenticationFilter@48d44b46, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@5cbe95b1, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@11ad095c, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@16a09809, org.springframework.security.web.session.SessionManagementFilter@1de85972, org.springframework.security.web.access.ExceptionTranslationFilter@4a122e68, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@5d37aa0f]
2019-11-05 14:33:32.392  INFO 39079 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2019-11-05 14:33:32.398  INFO 39079 --- [           main] eModelDeploymentServiceParentApplication : Started ServiceModelDeploymentServiceParentApplication in 5.727 seconds (JVM running for 6.778)

这是我的 pom 依赖项:

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</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-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.kafka</groupId>
            <artifactId>kafka-streams</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.kafka</groupId>
            <artifactId>spring-kafka</artifactId>
        </dependency>

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.kafka</groupId>
            <artifactId>spring-kafka-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
</dependencies>

注意:您可能不需要上述所有依赖项。

【讨论】:

  • 添加 spring-boot-starter-web 依赖解决了我的问题
【解决方案3】:

在 pom.xml 中添加以下依赖项:

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

【讨论】:

    【解决方案4】:

    添加 spring boot starter web 解决了我的问题

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

    【讨论】:

      【解决方案5】:

      在我的情况下,我开始使用 intelliJ

      管理员

      ,然后就可以了 确保你有tomcat依赖

       <dependency>
              <groupId>org.apache.tomcat.embed</groupId>
              <artifactId>tomcat-embed-core</artifactId>
              <version>9.0.29</version>
          </dependency>
      

      【讨论】:

        【解决方案6】:

        就我而言,两者之间存在细微差别:

        • 只需在 IntelliJ 内部最明显的底部单击“运行”,然后...
        • 在 src/main/java/com.exampler.yourapplication 中查找默认控制器,右键单击并在此处按运行。

        第二个选项只是正常运行项目。

        【讨论】:

        • 谢谢,第二个解决方案对我不起作用。但至少它显示了不同的错误......
        【解决方案7】:

        如果你从https://start.spring.io/(sprint initializr)创建一个项目gradle模板,你需要在你的build.gradle文件中添加org.springframework.boot:spring-boot-starter-webdependecy。

        // you need to add this dependency to run spring boot correctly
        implementation 'org.springframework.boot:spring-boot-starter-web'   
        

        【讨论】:

          【解决方案8】:

          如果将以下属性添加到 allication.properties 文件中,则需要将其删除。 此属性用于移除 Web 容器。

          spring.main.web-application-type=none

          在我的情况下,我忘了删除它,一旦它被删除,问题就解决了

          【讨论】:

            【解决方案9】:

            在 pom.xml 中使用以下依赖项,以及加载 maven 更改(ctrl+shift+o)解决了我的问题。

            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                </dependency>
            
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </dependency>
            
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-test</artifactId>
                    <scope>test</scope>
                </dependency>
            </dependencies>
            

            【讨论】:

              猜你喜欢
              • 2018-03-07
              • 1970-01-01
              • 2023-02-20
              • 2020-07-05
              • 2018-05-29
              • 2018-05-24
              • 1970-01-01
              • 1970-01-01
              • 2020-01-31
              相关资源
              最近更新 更多