Whitelabel 错误页面,其余 url 未在 spring boot 中执行
Whitelabel Error Page, rest urls not executed in springboot
spring 启动应用程序开发的新手。我 运行 应用程序作为 java 应用程序并收到以下错误。应用部署成功,不知道为什么会报这个错。。。脑袋疼。。先谢谢大家的帮助了。
Whitelabel Error Page This application has no explicit mapping for
/error, so you are seeing this as a fallback. Sat Jul 13 21:37:31 IST
2019 There was an unexpected error (type=Not Found, status=404). No
message available
已尝试针对堆栈溢出给出的解决方案,但无济于事。如果我在这里做错了,你能帮帮我吗?
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>
检查是否有class :
@SpringBootApplication
@ComponentScan("com.cgi.poc")
@ComponentScan
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
如果您有上述class,则无需在控制器上放置组件扫描。
使用 lsof 命令验证您的 java 服务在端口上 运行 not.
spring 启动应用程序开发的新手。我 运行 应用程序作为 java 应用程序并收到以下错误。应用部署成功,不知道为什么会报这个错。。。脑袋疼。。先谢谢大家的帮助了。
Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Sat Jul 13 21:37:31 IST 2019 There was an unexpected error (type=Not Found, status=404). No message available
已尝试针对堆栈溢出给出的解决方案,但无济于事。如果我在这里做错了,你能帮帮我吗?
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>
检查是否有class :
@SpringBootApplication
@ComponentScan("com.cgi.poc")
@ComponentScan
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
如果您有上述class,则无需在控制器上放置组件扫描。 使用 lsof 命令验证您的 java 服务在端口上 运行 not.