Thursday, January 2, 2014

Seeing what the spring container does without walking through the debugger.

If you're curious about what spring is doing, but don't want to walk through the source code as it's executing, one way to do it is to set the debug level for various spring components. For example, the Spring MVC template on STS creates a "log4j.xml" file under "src/main/resources".  All the default levels are set to "info".

However, you can change them to "debug" and you will see a lot more information from the console. For example, if you set the org.springframework.web to "debug", like so:

<logger name="org.springframework.web">
<level value="debug" />

</logger>

you can see the logic of the Spring MVC in action.

DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'appServlet' processing GET request for [/mvctest/]
DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Looking up handler method for path /
DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Returning handler method [public java.lang.String com.acme.mvctest.HomeController.home(java.util.Locale,org.springframework.ui.Model)]
DEBUG: org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'homeController'
DEBUG: org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/mvctest/] is: -1
INFO : com.acme.mvctest.HomeController - Welcome home! The client locale is en_US.
DEBUG: org.springframework.beans.factory.support.DefaultListableBeanFactory - Invoking afterPropertiesSet() on bean with name 'home'
DEBUG: org.springframework.web.servlet.DispatcherServlet - Rendering view [org.springframework.web.servlet.view.JstlView: name 'home'; URL [/WEB-INF/views/home.jsp]] in DispatcherServlet with name 'appServlet'
DEBUG: org.springframework.web.servlet.view.JstlView - Added model object 'serverTime' of type [java.lang.String] to request in view with name 'home'
DEBUG: org.springframework.web.servlet.view.JstlView - Forwarding to resource [/WEB-INF/views/home.jsp] in InternalResourceView 'home'

DEBUG: org.springframework.web.servlet.DispatcherServlet - Successfully completed request


No comments:

Post a Comment