springboot不会启动tomcat,它会立即退出并返回代码0

thtygnil  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(247)

编辑:我发现这是因为我的模块信息文件。每当我删除它的代码运行完美。有人知道为什么会引起这个问题吗?
我对springboot有意见。我的代码立即以代码0退出,而不是保持服务器运行。我在这里查看了多个线程,但它们都缺少此依赖关系:

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

但是,我确实在pom.xml中包含了这一点。我正在使用多个模块。我从一个只有一个模块的不同项目复制了大部分代码,不知何故,我认为使用多个模块与我现在遇到的问题有关。
这是我的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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.0</version>
        <relativePath/>
    </parent>
    <groupId>org.example</groupId>
    <artifactId>restful-server</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>restful-server</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>11</java.version>
    </properties>

    <dependencies>
        <!-- Spring Default -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <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>
        <!-- Hibernate -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.4.12.Final</version>
        </dependency>
        <!-- MYSQL -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.31</version>
        </dependency>
        <!-- Javax.ws.rs -->
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>javax.ws.rs-api</artifactId>
            <version>2.0</version>
        </dependency>
        <!-- Junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.example</groupId>
            <artifactId>shared</artifactId>
            <version>1.0-SNAPSHOT</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

控制台:

.   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.4.0)

2020-12-06 16:26:03.845  INFO 10848 --- [           main] restful.RestfulServerApplication         : Starting RestfulServerApplication using Java 11.0.5 on DESKTOP-UU1HOTF with PID 10848 (C:\Users\root\Documents\Git\FHICT\tictactoe\restful-server\target\classes started by root in C:\Users\root\Documents\Git\FHICT\tictactoe)
2020-12-06 16:26:03.847  INFO 10848 --- [           main] restful.RestfulServerApplication         : No active profile set, falling back to default profiles: default
2020-12-06 16:26:04.276  INFO 10848 --- [           main] restful.RestfulServerApplication         : Started RestfulServerApplication in 0.709 seconds (JVM running for 1.203)

Process finished with exit code 0

根据评论中的要求:

@SpringBootApplication
public class RestfulServerApplication {

    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(RestfulServerApplication.class);
        app.setDefaultProperties(Collections.singletonMap("server.port", "8083"));
        app.run(args);
    }

}

github链接: github.com/dmitrilisokonov/TicTacToe

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题