我使用STS IDE在我的工作区中运行了几个Spring Boot应用程序,在我对其中一个项目进行maven更新之后,每个项目都会在应用程序启动过程后立即停止。我甚至创造了最小的例子,只是为了开始一些事情,同样的事情发生了。
@SpringBootApplication
public class App implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
@Override
public void run(String... arg0) throws Exception {
System.out.println("Started...");
}
}
这是我的pom.xml
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>sasa-test-app</groupId>
<artifactId>sasa-app</artifactId>
<version>1.0.0</version>
<packaging>war</packaging>
<name>sasa-app</name>
<description>Sasa</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.BUILD-SNAPSHOT</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<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-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
这就是我在应用程序启动时获得的。我尝试了一些我可以在网上找到的建议 - 我在这里遗漏了一些东西。
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ [32m :: Spring Boot :: [39m[2m (v1.4.0.BUILD-SNAPSHOT)[0;39m [2m2016-07-10 22:35:25.204[0;39m [32m INFO[0;39m [35m10028[0;39m [2m---[0;39m [2m[ main][0;39m [36msasa_test_app.sasa_app.App [0;39m [2m:[0;39m Starting App on LAPTOP-C36O81UQ with PID 10028 (C:\Users\sasar\DEVCODE\STS_WORKSPACE\sasa-app\target\classes started by sasar in C:\Users\sasar\DEVCODE\STS_WORKSPACE\sasa-app) [2m2016-07-10 22:35:25.210[0;39m [32m INFO[0;39m [35m10028[0;39m [2m---[0;39m [2m[ main][0;39m [36msasa_test_app.sasa_app.App [0;39m [2m:[0;39m No active profile set, falling back to default profiles: default [2m2016-07-10 22:35:25.426[0;39m [32m INFO[0;39m [35m10028[0;39m [2m---[0;39m [2m[ main][0;39m [36ms.c.a.AnnotationConfigApplicationContext[0;39m [2m:[0;39m Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@641147d0: startup date [Sun Jul 10 22:35:25 CEST 2016]; root of context hierarchy [2m2016-07-10 22:35:29.004[0;39m [32m INFO[0;39m [35m10028[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.s.j.e.a.AnnotationMBeanExporter [0;39m [2m:[0;39m Registering beans for JMX exposure on startup Started... [2m2016-07-10 22:35:29.041[0;39m [32m INFO[0;39m [35m10028[0;39m [2m---[0;39m [2m[ main][0;39m [36msasa_test_app.sasa_app.App [0;39m [2m:[0;39m Started App in 4.664 seconds (JVM running for 5.876) [2m2016-07-10 22:35:29.070[0;39m [32m INFO[0;39m [35m10028[0;39m [2m---[0;39m [2m[ Thread-1][0;39m [36ms.c.a.AnnotationConfigApplicationContext[0;39m [2m:[0;39m Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@641147d0: startup date [Sun Jul 10 22:35:25 CEST 2016]; root of context hierarchy [2m2016-07-10 22:35:29.075[0;39m [32m INFO[0;39m [35m10028[0;39m [2m---[0;39m [2m[ Thread-1][0;39m [36mo.s.j.e.a.AnnotationMBeanExporter [0;39m [2m:[0;39m Unregistering JMX-exposed beans on shutdown
即使这些入门示例在启动后也会立即停止。我非常感谢你们的帮助。
编辑:正如Alexandru Marina在评论中所述,我使用的是SNAPSHOT而不是稳定版本。
答案 0 :(得分:3)
答案 1 :(得分:0)
而不是CommandLineRunner实现扩展类SpringBootServletInitializer或更好地阅读here文档。