[英]Spring boot whitelabel 404
大家好,即使我從他們的網站上關注了春季教程,我仍然會收到此錯誤。 我一直試圖弄清楚為什么我會收到這個錯誤。 我可以連接到Facebook但是當試圖檢索像春天提供的教程這樣的提要時,我不斷收到白標錯誤。 它說:
此應用程序沒有/ error的顯式映射,因此您將此視為回退。 出現意外錯誤(type = Not Found,status = 404)。 沒有可用的消息
一切似乎都沒問題,但不知道為什么我一直收到這個錯誤。 如果有人可以提供幫助我會很感激。
我的控制器放在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>
如果您的控制器采用不同的包結構,則需要將@ComponentScan
添加到Spring Boot
應用程序class
。
示例:
@ComponentScan(basePackages={"package name of where the controller is"})
如果您將控制器和存儲庫放在不同的包中,
然后@ComponentScan和@EnableMongoRepositories注釋,我們必須提供控制器和存儲庫的完整包名。
@ComponentScan(basePackages={"package name of controller", "package name of repository"})
@EnableMongoRepositories("package name of repository")
您可以嘗試使用以下內容
@RestController and produces = MediaType.APPLICATION_JSON_VALUE
例如
@RestController
public class MyController
@GetMapping(value = "/xyz/{ab}", produces = MediaType.APPLICATION_JSON_VALUE)
我有同樣的白標錯誤。 花了我幾個小時來弄清楚實際上百日咳依賴性沒有得到妥善解決。 解決方案非常簡單和愚蠢。
如果這不起作用,請更改build.gradle中下面一行的位置(向上或向下移動),然后執行上述步驟。
編譯(“org.springframework.boot:彈簧引導起動thymeleaf”)
重要的是,您必須在tomcat未運行時重新刷新項目。 如果我們使用devtools,我們會盲目地依賴它來重新啟動我們的servlet容器和東西,但有時手動啟動停止會很方便。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.