java - 即使使用 IDE(eclipse) 或命令提示符,Spring Boot 应用程序也无法启动并运行
问题描述
只需在 Eclipse 中创建一个 spring boot 应用程序并尝试运行它,但它没有正确启动,不足以处理请求。以下显示了控制台尝试了针对同一问题提出的其他问题的所有解决方案。但没有奏效。
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.6.RELEASE)
2018-10-22 14:12:42.929 INFO 5752 --- [ main] com.nevro.TrainingApiApp : Starting TrainingApiApp on DESKTOP-AUANCVF with PID 5752 (E:\MyStuff\Tutorials\spring-boot-training\target\classes started by acer in E:\MyStuff\Tutorials\spring-boot-training)
2018-10-22 14:12:42.932 INFO 5752 --- [ main] com.nevro.TrainingApiApp : No active profile set, falling back to default profiles: default
2018-10-22 14:12:43.004 INFO 5752 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@19d37183: startup date [Mon Oct 22 14:12:43 IST 2018]; root of context hierarchy
2018-10-22 14:12:43.758 INFO 5752 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-10-22 14:12:43.770 INFO 5752 --- [ main] com.nevro.TrainingApiApp : Started TrainingApiApp in 1.137 seconds (JVM running for 1.725)
2018-10-22 14:12:43.783 INFO 5752 --- [ Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@19d37183: startup date [Mon Oct 22 14:12:43 IST 2018]; root of context hierarchy
2018-10-22 14:12:43.785 INFO 5752 --- [ Thread-2] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
它说应用程序已启动,但是当尝试浏览它时,除了浏览器中的错误之外别无其他。
tomcat (8080) 的默认端口是 unoccupied 。
这是 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>com.nevro</groupId>
<artifactId>spring-training</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-theory training</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.6.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
</project>
这是带有 main 方法的 Main 类
package com.nevro;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class TrainingApiApp {
public static void main(String[] args) {
SpringApplication.run(TrainingApiApp.class, args);
}
}
也有一个控制器如下
package controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@RequestMapping("/hello")
public String sayHi(){
return "hi";
}
}
任何原因以及如何解决此问题。
解决方案
Spring Boot 会自动检测com.nevro
和 子包中的所有 bean。但是,您的控制器在controller
包中,因此永远不会被检测到。将控制器移动到com.nevro.controller
包中,这将使 Spring Boot 检测到控制器并帮助决定是否需要启动 Web 服务器。
也可能是其中一个依赖项未正确下载。您可能希望使用 清除本地存储库mvn dependency:purge-local-repository
,然后重建应用程序以重新下载依赖项。
推荐阅读
- java - 如何访问 arrayList 内的类的实例
- ios - 在 iOS 蓝牙设置中使 UWP 应用程序可发现
- python - 如何让 2 个“朋友”比较,看看他们是否在彼此的朋友列表中?
- java - Oracle rdb - 找不到 rdbthin-7.4.3.1-jar。谁能提供下载链接
- javascript - 无法在 Invertase 的 React Native Firebase 中使用 Cloud Firestore 查询分配变量值
- walmart-api - Walmart IO API:未订阅服务名称
- typescript - 打字稿联合类型到单个映射类型
- chromecast - 如何在基于网络的发件人上接收来自 Google Cast Receiver 的消息?
- python - 如何重塑测试数据框,使维度与训练和预测工作中使用的维度相同?
- python - 使用 Imagemagik 将未嵌入字体的 pdf 转换为 png