Uma*_*mar 7 java spring spring-boot
我正在尝试一个简单的弹簧启动应用程序,它总是自动关闭
:: 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
Run Code Online (Sandbox Code Playgroud)
的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>
Run Code Online (Sandbox Code Playgroud)
主类
@SpringBootApplication
public class RestBootApplication {
public static void main(String[] args) {
SpringApplication.run(RestBootApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
调节器
@Controller
public class HelloController {
@RequestMapping("/hello")
String helloWorld(){
return "helloWorld";
}
}
Run Code Online (Sandbox Code Playgroud)
试图在spring工具套件中运行.它总是在开始后停止.在查看了一些stackoverflow问题之后,我甚至添加了"spring-boot-starter-web",但仍然面临着这个问题.
请问有人可以指出这个问题.
Dar*_*man 15
这发生在我身上,结果证明是一个损坏的maven apache存储库.
为了解决这个问题,我删除了apache repo - 在我的Mac上,它位于/Users/myname/.m2/repository/org/apache.
在PC上它应该是c:\ users\myname.m2\repository\org\apache.
然后我运行了Maven - Update Project,然后我运行了我的课程并修复了它.
jde*_*dev 10
在我的情况下,只需在pom文件中添加以下内容
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
检查您获得的退出代码。
如果您收到“进程已完成,退出代码为 1”,则表示正在引发异常。因此,您可以在语句周围放置一个 try catch 块SpringApplication.run()并打印出堆栈跟踪。
public static void main(String[] args) {
try {
SpringApplication.run(MyApplication.class, args);
} catch (Exception e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
示例来自:https ://stackoverflow.com/a/59017774/9531109
我的建议是删除这种依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
您还可以尝试添加此 tomcat 依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>1.4.1.RELEASE</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18080 次 |
| 最近记录: |