Spring boot whitelabel 404
Hi guys, I keep getting this error even though I followed the spring tutorial from their site. I was trying to figure out why I am getting this error. I can connect to facebook, but when trying to get feeds like the tutorial provided by spring, I still get a whitelabel error. It says:
This app doesn't have an explicit mapping for / error, so you see that as a fallback. An unexpected error occurred (type = Not Found, status = 404). No messages available
Everything seems to be fine, but not sure why I keep getting this error. if anyone can help i would appreciate it.
My controller is 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";
}
}
The Application.java file is located at src / main / java / home / main:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
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 file: it is 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: It is stored in 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>
And finally facebookConnected.html: is also stored in 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>
source to share
If you put controllers and repositories in different packages,
then @ComponentScan and @EnableMongoRepositories , we have to provide the full name of the controller and repository package.
@ComponentScan(basePackages={"package name of controller", "package name of repository"})
@EnableMongoRepositories("package name of repository")
source to share