Java 当 spring-boot 运行时,IntelliJ 进程以退出代码 0 完成

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32758996/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 13:02:05  来源:igfitidea点击:

IntelliJ Process finished with exit code 0 when spring-boot run

javaspringintellij-ideaspring-boot

提问by Greg Zuber

I have a problem when starting spring-boot appication from IntelliJ-Idea. I don't have this problem when running application through terminal.

从 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

I think this warn is not causing it. What may be the reason?

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

采纳答案by Aleksandr Sakharov

Deleting providedscope of spring-boot-starter-tomcatdependency helps me.

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

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

回答by Abd Abughazaleh

Add the below dependencies in pom.xml :

在 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>

回答by Rishabh Agarwal

I create a simple project from https://start.spring.io/(sprint initializr) and added a simple controller to run the application.

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

@RestController
public class testController {

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

but it wasn't getting started because my pom wasn't having

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

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

After adding this my application started...

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

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)

Here are my pom dependencies:

这是我的 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>

Note: You may be not needing all the dependencies above.

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

回答by Mohamed.Abdo

in my case i started intelliJ as

在我的情况下,我开始 intelliJ 作为

adminstrator

管理员

, then it works make sure you have tomcat dependency

,然后它的工作原理确保你有 tomcat 依赖

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