2017-09-19 118 views
0

我正在使用inbuild tomcat服务器构建一个非常基本的spring-boot服务。春季启动内置tomcat服务器不启动

双响炮看起来是这样的:

<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设置端口。有一个平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.spring[email protected]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.springfra[email protected]99a05: 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 

日志没有显示什么端口的服务正在启动。

还有什么要做,以启动指定端口上的服务,并保持服务器运行?

+2

对于初学者,删除'spring-web'依赖项。删除编译器插件并重新添加'spring-boot-maven-plugin'。另外你如何运行'main'方法?命令行? IDE?或者?... –

+0

告诉你什么,尽管它没有真正相关,但我会尽快从代码中删除lombok。这是一个残酷的想法。 –

+0

@ M.Deinum - 根据你的建议重新添加了spring-boot-maven -plugin,这次通过** spring-boot:start **选项启动服务器。现在在日志中,我看到应用程序从端口8089开始,但服务器再次停止。 – worrynerd

回答

0

解决了这个问题。使用spring-boot启动内置的tomcat服务器:运行选项