问题描述
我正在尝试一个简单的spring启动应用程序,它总是自动关闭
:: Spring Boot ::(v1。 4.1.RELEASE)
2016-10-23 13:05:21.681 INFO 16532 --- [main] com.example.RestBootApplication:没有活动的配置文件集,回退到默认配置文件:默认
2016- 10-23 13:05:21.766 INFO 16532 --- [main] scaAnnotationConfigApplicationContext:刷新org.springframework.context.annotation.AnnotationConfigApplicationContext@6e20b53a:启动日期[Sun Oct 23 13:05:21 EDT 2016];上下文层次结构
2016-10-23 13:05:23.682 INFO 16532 --- [main] osjeaAnnotationMBeanExporter:在启动时为JMX曝光注册bean
2016-10-23 13:05:23.704 INFO 16532 --- [main] com.example.RestBootApplication:在2.632秒内启动RestBootApplication(JVM运行5.168)
2016-10-23 13:05:23.705 INFO 16532 --- [Thread-2] sca AnnotationConfigApplicationContext:关闭org.springframework.context.annotation.AnnotationConfigApplicationContext@6e20b53a:启动日期[Sun Oct 23 13:05:21 EDT 2016];上下文层次结构的根源
2016-10-23 13:05:23.708 INFO 16532 --- [Thread-2] osjeaAnnotationMBeanExporter:在关闭时取消注册JMX暴露的bean
pom.xml
<?xml version = 1.0encoding =UTF-8?>
< project xmlns =http://maven.apache.org/POM/4.0.0xmlns: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> com.example< / groupId>
< artifactId> demo< / artifactId>
< version> 0.0.1-SNAPSHOT< / version>
< packaging> jar< / packaging>
< name> rest-boot< / name>
< description> Spring Boot的演示项目< / description>
< parent>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-parent< / artifactId>
< version> 1.4.1.RELEASE< / version>
< relativePath /> <! - 从存储库查找父级 - >
< / 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< / artifactId>
< / dependency>
< 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>
< / project>
主类
@SpringBootApplication
public class RestBootApplication {
public static void main(String [] args){
SpringApplication.run(RestBootApplication.class,args);
}
}
控制器
@Controller
public class HelloController {
@RequestMapping(/ hello)
String helloWorld(){
返回helloWorld;
}
}
尝试在spring工具套件中运行。它总是在开始后停止。在查看了一些stackoverflow问题之后,我甚至添加了spring-boot-starter-web,但仍然面临着这个问题。
请你指点一下这个问题。
这发生在我身上,结果证明是一个损坏的maven apache存储库。
要修复它,我删除了apache repo - 在我的Mac上,它位于/Users/myname/.m2/repository/org/apache。
在电脑上它应该是c:\ usersrs \myname.m2 \\\ store \\\\\\\\\\\\\\\\\\\ b $ b
然后我运行了Maven - 更新项目,然后我运行了我的课程并修复了它。
I am trying out a simple spring boot application it always shuts down automatically
:: Spring Boot :: (v1.4.1.RELEASE)
2016-10-23 13:05:21.681 INFO 16532 --- [ main] com.example.RestBootApplication : No active profile set, falling back to default profiles: default
2016-10-23 13:05:21.766 INFO 16532 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@6e20b53a: startup date [Sun Oct 23 13:05:21 EDT 2016]; root of context hierarchy
2016-10-23 13:05:23.682 INFO 16532 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2016-10-23 13:05:23.704 INFO 16532 --- [ main] com.example.RestBootApplication : Started RestBootApplication in 2.632 seconds (JVM running for 5.168)
2016-10-23 13:05:23.705 INFO 16532 --- [ Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@6e20b53a: startup date [Sun Oct 23 13:05:21 EDT 2016]; root of context hierarchy
2016-10-23 13:05:23.708 INFO 16532 --- [ Thread-2] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>rest-boot</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.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</artifactId>
</dependency>
<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>
</project>
Main Class
@SpringBootApplication
public class RestBootApplication {
public static void main(String[] args) {
SpringApplication.run(RestBootApplication.class, args);
}
}
Controller
@Controller
public class HelloController {
@RequestMapping("/hello")
String helloWorld(){
return "helloWorld";
}
}
Trying to run in spring tool suite. it always stops after starting. I even added "spring-boot-starter-web" after looking at some stackoverflow questions, but still facing the issue.
Please can you someone point out the issue.
This was happening to me and it turned out to be a corrupted maven apache repository.
To fix it I removed the apache repo - on my Mac it was located at /Users/myname/.m2/repository/org/apache.
On a pc it should be c:\users\myname.m2\repository\org\apache.
I then ran Maven - Update Project and then I ran my class and it was fixed.
这篇关于Spring Boot App在启动时终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!