Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Spring Basics Creating Controllers and Views Create a Controller to Handle HTTP Requests

Sergei Makarov
Sergei Makarov
13,839 Points

See nothing but Whitelabel Error Page

2016-04-13 19:45:56.161 INFO 417 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http) 2016-04-13 19:45:56.217 INFO 417 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat 2016-04-13 19:45:56.221 INFO 417 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.0.32 2016-04-13 19:45:56.525 INFO 417 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2016-04-13 19:45:56.526 INFO 417 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 4250 ms 2016-04-13 19:45:57.767 INFO 417 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/] 2016-04-13 19:45:57.805 INFO 417 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/] 2016-04-13 19:45:57.806 INFO 417 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/] 2016-04-13 19:45:57.807 INFO 417 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/] 2016-04-13 19:45:57.807 INFO 417 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/] 2016-04-13 19:45:58.957 INFO 417 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@10d59286: startup date [Wed Apr 13 19:45:52 EEST 2016]; root of context hierarchy 2016-04-13 19:45:59.121 INFO 417 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest) 2016-04-13 19:45:59.123 INFO 417 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) 2016-04-13 19:45:59.227 INFO 417 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2016-04-13 19:45:59.242 INFO 417 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2016-04-13 19:45:59.356 INFO 417 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2016-04-13 19:45:59.595 INFO 417 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup 2016-04-13 19:45:59.787 INFO 417 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http) 2016-04-13 19:45:59.798 INFO 417 --- [ main] giflib.AppConfig : Started AppConfig in 9.177 seconds (JVM running for 10.362) 2016-04-13 19:46:02.239 INFO 417 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet' 2016-04-13 19:46:02.240 INFO 417 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started 2016-04-13 19:46:02.291 INFO 417 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 49 ms

As you can see, there is no any mapping to my request [/] referencing the method 'listGifs()'

So, by any request at localhost:8080 i see just an error page. Everything was made absolute the same as in the tutorial video. Moreover, everything was smooth with the same project one week ago. The one thing, i've made within those time, 've updated Java to 1.8.0.77 (before was 1.8.0.66). Could it matter?

Sergei Makarov
Sergei Makarov
13,839 Points

GifController.java

package controller;

import java.io.IOException;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class GifController {
    @RequestMapping("/") 
    @ResponseBody
    public String listGifs() throws IOException{
        return "List of all Gifs";
    }
}

AppConfig.java

package giflib;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;

@EnableAutoConfiguration
@ComponentScan
public class AppConfig {
    public static void main(String[] args){
        SpringApplication.run(AppConfig.class, args);
    }
}

1 Answer

Sergei Makarov
Sergei Makarov
13,839 Points

Done!

I've should to set an parameter for @ComponentScan. I suppose it is on the different structure of project, cause i work in Eclipse. But everything is ok now!