Spring Boot 1.5.3 Web应用程序在启动后立即终止

时间:2017-05-10 08:06:42

标签: maven spring-boot

启动在1.5.3.RELEASE上运行的Spring Boot Project后,运行的日志会强行停止

任何人都知道为什么1.5.3会停止,我试过1.4.6成功启动

的pom.xml

<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.3.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

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

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

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

申请

import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;

@SpringBootApplication
@Controller
@EnableAutoConfiguration
public class DemoApplication {

    @RequestMapping("/")
    @ResponseBody
    String home() {
        return "Hello World!";
    }

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}

记录

[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------------------------------------------------------
---
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] ---------------------------------------------------------------------
---
[INFO]
[INFO] >>> spring-boot-maven-plugin:1.5.3.RELEASE:run (default-cli) > test-
compile @ demo >>>
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ demo ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\Workspace\spring\demo\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ demo ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] <<< spring-boot-maven-plugin:1.5.3.RELEASE:run (default-cli) < test-compile @ demo <<<
[INFO]
[INFO]
[INFO] --- spring-boot-maven-plugin:1.5.3.RELEASE:run (default-cli) @ demo ---
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.5.3.RELEASE)

2017-05-10 15:25:09.638  INFO 11112 --- [           main] com.example.DemoApplication              : Starting DemoApplication on WutikornMat with PID 11112 (D:\Workspace\sp
ring\demo\target\classes started by sutee.cha in D:\Workspace\spring\demo)
2017-05-10 15:25:09.643  INFO 11112 --- [           main] com.example.DemoApplication              : No active profile set, falling back to default profiles: default
2017-05-10 15:25:09.739  INFO 11112 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigAppli
cationContext@3a723bfc: startup date [Wed May 10 15:25:09 ICT 2017]; root of context hierarchy
2017-05-10 15:25:10.599  INFO 11112 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2017-05-10 15:25:10.617  INFO 11112 --- [           main] com.example.DemoApplication              : Started DemoApplication in 1.599 seconds (JVM running for 5.332)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.069 s
[INFO] Finished at: 2017-05-10T15:25:10+07:00
[INFO] Final Memory: 33M/398M
[INFO] ------------------------------------------------------------------------
2017-05-10 15:25:10.751  INFO 11112 --- [       Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicat
ionContext@3a723bfc: startup date [Wed May 10 15:25:09 ICT 2017]; root of context hierarchy
2017-05-10 15:25:10.754  INFO 11112 --- [       Thread-2] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown

然后我通过IDE外的命令行运行jar

2017-05-10 15:38:57.630  INFO 7532 --- [           main] com.example.DemoApplication              : Starting DemoApplication v0.0.1-SNAPSHOT on WutikornMat with PID 7532 (D
:\Workspace\spring\demo\target\demo-0.0.1-SNAPSHOT.jar started by sutee.cha in D:\Workspace\spring\demo\target)
2017-05-10 15:38:57.638  INFO 7532 --- [           main] com.example.DemoApplication              : No active profile set, falling back to default profiles: default
2017-05-10 15:38:57.765  INFO 7532 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplic
ationContext@255316f2: startup date [Wed May 10 15:38:57 ICT 2017]; root of context hierarchy
2017-05-10 15:38:58.973  INFO 7532 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2017-05-10 15:38:58.997  INFO 7532 --- [           main] com.example.DemoApplication              : Started DemoApplication in 1.888 seconds (JVM running for 2.455)
2017-05-10 15:38:59.000  INFO 7532 --- [       Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicati
onContext@255316f2: startup date [Wed May 10 15:38:57 ICT 2017]; root of context hierarchy
2017-05-10 15:38:59.003  INFO 7532 --- [       Thread-2] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown

因此,您可以看到设置和示例与spring docs

完全相同

我在1.5.3错过了什么

提前致谢

1 个答案:

答案 0 :(得分:0)

如果查看current example,则没有@SpringBootApplication注释,但

@RestController
@EnableAutoConfiguration
public class DemoApplication {

这个开箱即用。如果我开始你的例子,我得到

** WARNING ** : Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package.

如果我将类从默认包移动到任何包 - 让我们说demo - 应用程序正确启动。