java - Spring Boot 白标 404

标签 java html gradle spring-boot spring-social-facebook

大家好,即使我已经按照他们网站上的 spring 教程进行操作,我仍然会收到此错误。我一直在努力弄清楚为什么会出现此错误。我能够连接到 facebook,但是当尝试像 spring 提供的教程那样检索提要时,我不断收到白标签错误。它说:

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

一切似乎都很好,但不知道为什么我一直收到这个错误。如果有人可以提供帮助,我将不胜感激。

我的 Controller 放在 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:

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

下面是我的 build.gradle 文件:

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 文件夹中:

<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 文件夹下:

 <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 的文件:

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

最佳答案

如果您的 Controller 处于不同的包结构中,则 @ComponentScan需要添加到 Spring Boot应用class .

示例:

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

关于java - Spring Boot 白标 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29870852/

相关文章:

HTML/CSS : Hide Text and Show Border

android - 无法确定任务 ':app:installDebug' 对 visual studio 代码的 native react 的依赖性

Gradle:在配置和执行阶段之间拆分复制任务

javascript - 使用 jquery 从 select 中识别选项

variables - Gradle:在范围内定义变量?

java - Android键盘的自定义键

java - 是否有任何现成的 Java 库可用于通过 TCP 传输图像?

Java:使用class in读取文件。为什么没有输出?

java - 最小堆是如何创建的?

php - PHP 和 MySQL 上的 INNER JOIN 和 foreach 循环