java - Whitelabel 错误页面,其余 url 未在 springboot 中执行
问题描述
Spring Boot 应用程序开发的新手。我将应用程序作为 java 应用程序运行并得到以下错误。应用程序部署成功,我不知道为什么会出现这个错误......打我的头......谢谢你的帮助。
Whitelabel 错误页面 此应用程序没有针对 /error 的显式映射,因此您将其视为后备。IST 2019 年 7 月 13 日星期六 21:37:31 出现意外错误(类型=未找到,状态=404)。没有可用的消息
尝试了有关堆栈溢出的解决方案,但没有帮助。如果我在这里做错了,你能帮我吗?
package com.cpi.poc.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cpi.poc.service.IService;
@RestController
@RequestMapping(value ="/test")
@ComponentScan(basePackages = "com.cgi.poc")
public class TestController {
@Autowired
IService service;
@RequestMapping(value = "/greet" , method = RequestMethod.GET)
public String testService(){
String result = service.greet();
return result;
}
}
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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.21.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.cgi.poc</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>test</name>
<description>Demo project for Spring Boot</description>
<properties>
<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>
<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>
解决方案
检查你是否有课:
@SpringBootApplication
@ComponentScan("com.cgi.poc")
@ComponentScan
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
如果您有上述课程,则无需在控制器上进行组件扫描。使用 lsof 命令验证您的 java 服务是否在端口上运行。
推荐阅读
- java - #姓名!通过 apache POI 将用户定义的“SpellNumber”函数设置为 excel 单元格时出错
- python - 根据给定坐标从 jpeg 或 tiff 图像创建 LAS 文件
- javascript - 未捕获的引用,数组未在 JavaScript Chrome 控制台中定义
- c - 代码在 DEV C++ 上运行良好,但在 Hacker Rank 的测试用例中出现分段错误
- python - ValueError:未能找到可以处理输入的数据适配器:
, - python - 如何从csv打印出json数据
- html - Angular HTML文件中的下拉列表过滤器
- c# - 用 C# 快速下载 HTML 源代码
- python - django.core.cache.lock 在 Celery 任务中不起作用
- botframework - Bot 连接器 API:直接向 aadObjectId 发送消息