简体   繁体   English

Whitelabel错误页面,在springboot中未执行其他URL

[英]Whitelabel Error Page, rest urls not executed in springboot

new to spring boot application development. Spring Boot应用程序开发的新功能。 I ran the application as java application and got the below error. 我将应用程序作为Java应用程序运行,并收到以下错误。 THe application is deployed successfully , I don't know why this error is rendered ... beating my head.. thank you for your help in advance. 该应用程序已成功部署,我不知道为什么会出现此错误...击败了我的头..谢谢您的提前帮助。

Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Whitelabel Error Page此应用程序没有针对/ error的显式映射,因此您将其视为后备。 Sat Jul 13 21:37:31 IST 2019 There was an unexpected error (type=Not Found, status=404). IST 2019年7月13日星期六21:37:31发生意外错误(类型=未找到,状态= 404)。 No message available 无讯息

tried solutions given on stack overflow but no help. 尝试给出堆栈溢出但没有帮助的解决方案。 could you please help me if anywhere I do wrong here. 如果我在这里做错了什么,请您能帮助我。

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 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>

Check whether you have class : 检查您是否上课:

@SpringBootApplication
@ComponentScan("com.cgi.poc")
@ComponentScan
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

No need to put component scan on controller if you have the above class. 如果您具有上述类,则无需在控制器上进行组件扫描。 Verify by using lsof command that your java service is running on the port on not. 使用lsof命令验证Java服务是否在非端口上运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM