Spring-boot内置tomcat服务器无法启动

时间:2017-09-19 17:40:08

标签: java maven spring-boot

我正在使用inbuild tomcat服务器构建一个非常基本的spring-boot服务。

Pom看起来像这样:

<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.7.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <!--<dependency>
        <groupId>org.flywaydb</groupId>
        <artifactId>flyway-core</artifactId>
    </dependency>-->
    <!--<dependency>-->
        <!--<groupId>org.springframework.boot</groupId>-->
        <!--<artifactId>spring-boot-starter-jdbc</artifactId>-->
    <!--</dependency>-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-validation</artifactId>
    </dependency>

    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.restdocs</groupId>
        <artifactId>spring-restdocs-mockmvc</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

<build>
    <plugins>
        <!--<plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>-->


            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
    </plugins>
</build>

我将application.properties文件中的端口设置为server.port=8089。控制器类中添加了一个Ping URI:

@RequestMapping("/ping")
@RestController
public class helloController {

    @RequestMapping(method= RequestMethod.GET,produces = {MediaType.APPLICATION_JSON_VALUE})
    public ResponseEntity<String> ping(){
        return new ResponseEntity<>("Hello World Spring-boot app", HttpStatus.OK);
    }

当我做mvn clean package时,一切正常,构建成功。但是当我从Main()运行应用程序时,这就是日志的样子:

2017-09-19 10:37:32.219  INFO 6436 --- [           main] com.example.demo.DemoApplication         : No active profile set, falling back to default profiles: default
2017-09-19 10:37:32.290  INFO 6436 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@77f99a05: startup date [Tue Sep 19 10:37:32 PDT 2017]; root of context hierarchy
2017-09-19 10:37:33.782  INFO 6436 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2017-09-19 10:37:33.802  INFO 6436 --- [           main] com.example.demo.DemoApplication         : Started DemoApplication in 2.043 seconds (JVM running for 2.802)
2017-09-19 10:37:33.802  INFO 6436 --- [       Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@77f99a05: startup date [Tue Sep 19 10:37:32 PDT 2017]; root of context hierarchy
2017-09-19 10:37:33.802  INFO 6436 --- [       Thread-2] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown

日志未显示服务正在启动的端口。

在指定端口上启动服务以及使服务器保持运行还需要做些什么?

1 个答案:

答案 0 :(得分:0)

解决了这个问题。使用spring-boot:run选项

启动内置的tomcat服务器