春季启动whitelabel 404 [英] Spring boot whitelabel 404

查看:229
本文介绍了春季启动whitelabel 404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我一直在收到这个错误,即使我从他们的网站上浏览了Spring教程。我一直在努力弄清楚为什么我得到这个错误。我能够连接到Facebook,但当试图检索像Spring提供的教程那样的Feed时,我不断收到白标签错误。它说:

Hello guys I keep getting this error even though I have followed spring tutorial from their website. I have been trying to figure it out why I'm getting this error. I am able to connect to facebook but when trying to retrieve the feeds like the tutorial provided by spring, I keep getting a whitelabel error. It says:


这个应用程序没有明确的映射/错误,所以你将这看作是后备。有一个意外的错误(type = Not Found,status = 404)。没有消息可用

This application has no explicit mapping for /error, so you are seeing this as a fallback. There was an unexpected error (type=Not Found, status=404). No message available

一切似乎都没问题,但不知道为什么我一直收到这个错误。如果有人可以协助,我会欣赏它。

Everything seems to be okay but dont know why I keep getting this error. if someone can assist I will appreciate it.

我的控制器放在src / main / java / home中:

My controller placed in src/main/java/home:

@Controller
@RequestMapping(value="/")
public class HomeController {

private Facebook facebook;

@Inject
public HomeController(Facebook facebook) {
    this.facebook = facebook;
}

@RequestMapping( method =RequestMethod.GET)
public String getPhotos(Model model){

    if(!facebook.isAuthorized())
    {
        return "redirect:/connect/facebook";
    }
    model.addAttribute(facebook.userOperations().getUserProfile());
    PagedList<Post> homeFeed = facebook.feedOperations().getHomeFeed();
    model.addAttribute("feed", homeFeed);

    return "hello";
 }
}

将Application.java文件放置在src / main / java / home / main:

Application.java file placed in src/main/java/home/main:

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

以下是我的build.gradle文件:

Below is my build.gradle file:

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'

buildscript{
repositories{
   // maven { url "https://repo.spring.io/release" }
    maven { url "https://repo.spring.io/libs-milestone"}
   // mavenCentral()
      }
dependencies {
    classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.3.RELEASE")
  }
 }
repositories {
   maven { url "https://repo.spring.io/libs-milestone"}
   mavenCentral()
 }
bootRepackage {
  mainClass = 'facebookArchiver.Application'
}
 dependencies {
  compile ('org.springframework.social:spring-social-facebook:2.0.0.RELEASE')
  compile("org.springframework.boot:spring-boot-starter-thymeleaf")
  compile('org.springframework.boot:spring-boot-starter-web')
  testCompile group: 'junit', name: 'junit', version: '4.11'
 }
 task wrapper(type: Wrapper) {
      gradleVersion = '2.3'
 }

hello.html文件:保存在src / main / resources / templates文件夹中:

hello.html file: It's saved in src/main/resources/templates folder:

<html>
 <head>
<title>Hello Facebook</title>
</head>
<body>
 <h3>Hello, <span th:text="${facebookProfile.name}">Some User</span>!</h3>

 <h4>Here is your home feed:</h4>

 <div th:each="post:${feed}">
 <b th:text="${post.from.name}">from</b> wrote:
 <p th:text="${post.message}">message text</p>
 <img th:if="${post.picture}" th:src="${post.picture}"/>
 <hr/>
 </div>
</body>
</html>

facebookConnect.html:它存储在src / main / resources / templates / connect文件夹下:

facebookConnect.html: it's stored under src/main/resources/templates/connect folder:

 <html>
 <head>
 <title>Hello Facebook</title>
 </head>
 <body>
  <h3>Connect to Facebook</h3>

  <form action="/connect/facebook" method="POST">
<input type="hidden" name="scope" value="read_stream" />
  <div class="formInfo">
    <p>You aren't connected to Facebook yet. Click the button to connect  this application with your Facebook account.</p>
 </div>
 <p><button type="submit">Connect to Facebook</button></p>
</form>
</body>
</html>

最后facebookConnected.html:也保存在​​src / main / resources / templates / connect文件夹下:是facebookConnected.html的文件:

And finally facebookConnected.html: also stored under src/main/resources/templates/connect folder: Below is the file for facebookConnected.html:

<html>
<head>
  <title>Hello Facebook</title>
</head>
  <body>
   <h3>Connected to Facebook</h3>
   <p>
     You are now connected to your Facebook account.
    Click <a href="/">here</a> to see some entries from your Facebook photos.
  </p>
</body>
</html>


推荐答案

如果您的控制器处于不同的封装结构中, @ComponentScan 需要添加到 Spring Boot 应用程序 class

If your controllers are in a different package structure, then @ComponentScan needs to be added to the Spring Boot application class.

示例:

Example :

@ComponentScan(basePackages={"package name of where the controller is"})

这篇关于春季启动whitelabel 404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆