SpringBoot does not find views - java

I'm trying to write a simple SpringBoot Web Application to get started with the framework.
This is my structure:
src
`-main
`-java
`-resources
`-static
`-templates
`-webapp
`-WEB-INF
`-jsp
`-login.jsp
I have a Controller like
#Controller
public class LoginController {
#RequestMapping("/login")
public String loginMessage(){
return "login";
}
}
I've configurated the path where views has to be looked for in the application.properties like:
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
logging.level.org.springframework.web=DEBUG
I've also included the next dependency in pom.xml:
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
But when I go to http://localhost:8080/login I'm still having a 404 error.
What am I missing?
EDIT:
Here is the log from the IntelliJ Idea console. It seems like it finds the login.jsp, but for some reason return an error page.
2018-07-06 11:17:20.488 DEBUG 53340 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/login]
2018-07-06 11:17:20.488 DEBUG 53340 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /login
2018-07-06 11:17:20.488 DEBUG 53340 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method [public java.lang.String com.albertocastano.apringboot.web.springbootfirstwebapplication.controller.LoginController.loginMessage()]
2018-07-06 11:17:20.488 DEBUG 53340 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Last-Modified value for [/login] is: -1
2018-07-06 11:17:20.489 DEBUG 53340 --- [nio-8080-exec-1] o.s.w.s.v.ContentNegotiatingViewResolver : Requested media types are [text/html, application/xhtml+xml, image/webp, image/apng, application/xml;q=0.9, */*;q=0.8] based on Accept header types and producible media types [*/*])
2018-07-06 11:17:20.489 DEBUG 53340 --- [nio-8080-exec-1] o.s.w.servlet.view.BeanNameViewResolver : No matching bean found for view name 'login'
2018-07-06 11:17:20.489 DEBUG 53340 --- [nio-8080-exec-1] o.s.w.s.v.ContentNegotiatingViewResolver : Returning [org.springframework.web.servlet.view.InternalResourceView: name 'login'; URL [/WEB-INF/jsp/login.jsp]] based on requested media type 'text/html'
2018-07-06 11:17:20.489 DEBUG 53340 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Rendering view [org.springframework.web.servlet.view.InternalResourceView: name 'login'; URL [/WEB-INF/jsp/login.jsp]] in DispatcherServlet with name 'dispatcherServlet'
2018-07-06 11:17:20.492 DEBUG 53340 --- [nio-8080-exec-1] o.s.w.servlet.view.InternalResourceView : Forwarding to resource [/WEB-INF/jsp/login.jsp] in InternalResourceView 'login'
2018-07-06 11:17:20.492 DEBUG 53340 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/WEB-INF/jsp/login.jsp]
2018-07-06 11:17:20.492 DEBUG 53340 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /WEB-INF/jsp/login.jsp
2018-07-06 11:17:20.493 DEBUG 53340 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Did not find handler method for [/WEB-INF/jsp/login.jsp]
2018-07-06 11:17:20.495 DEBUG 53340 --- [nio-8080-exec-1] o.s.w.s.handler.SimpleUrlHandlerMapping : Matching patterns for request [/WEB-INF/jsp/login.jsp] are [/**]
2018-07-06 11:17:20.496 DEBUG 53340 --- [nio-8080-exec-1] o.s.w.s.handler.SimpleUrlHandlerMapping : URI Template variables for request [/WEB-INF/jsp/login.jsp] are {}
2018-07-06 11:17:20.497 DEBUG 53340 --- [nio-8080-exec-1] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapping [/WEB-INF/jsp/login.jsp] to HandlerExecutionChain with handler [ResourceHttpRequestHandler [locations=[class path resource [META-INF/resources/], class path resource [resources/], class path resource [static/], class path resource [public/], ServletContext resource [/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver#3f0408]]] and 1 interceptor
2018-07-06 11:17:20.498 DEBUG 53340 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Last-Modified value for [/WEB-INF/jsp/login.jsp] is: -1
2018-07-06 11:17:20.499 DEBUG 53340 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
2018-07-06 11:17:20.499 DEBUG 53340 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Successfully completed request
2018-07-06 11:17:20.500 DEBUG 53340 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Successfully completed request
2018-07-06 11:17:20.501 DEBUG 53340 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/error]
2018-07-06 11:17:20.502 DEBUG 53340 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /error
2018-07-06 11:17:20.502 DEBUG 53340 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method [public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)]
2018-07-06 11:17:20.502 DEBUG 53340 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Last-Modified value for [/error] is: -1
2018-07-06 11:17:20.522 DEBUG 53340 --- [nio-8080-exec-1] o.s.w.s.v.ContentNegotiatingViewResolver : Requested media types are [text/html, text/html;q=0.8] based on Accept header types and producible media types [text/html])
2018-07-06 11:17:20.522 DEBUG 53340 --- [nio-8080-exec-1] o.s.w.s.v.ContentNegotiatingViewResolver : Returning [org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$SpelView#bd7588] based on requested media type 'text/html'
2018-07-06 11:17:20.522 DEBUG 53340 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Rendering view [org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$SpelView#bd7588] in DispatcherServlet with name 'dispatcherServlet'
2018-07-06 11:17:20.522 DEBUG 53340 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Successfully completed request

You're missing dependancy in your pom.xml file.
Add jstl :
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
And remove the scope provided of tomcat-embed-jasper, because it's not provided by default by any spring-boot-starter.

Related

Spring Security SecurityFilterChain not working

I have a Spring Boot 3 project which has both web pages and an API. The REST API should be open (and use API keys) and the rest of the application will be authenticated. I have a separate filter which handles the key checking.
For example, if I do not supply an API key, and I use this security config, it does not return the correct JSON error and instead forward me to the login page.
#Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests()
.requestMatchers("/api/**").permitAll()
.requestMatchers(EndpointRequest.to(HealthEndpoint.class)).permitAll()
.requestMatchers("/actuator/*").hasAuthority("ADMIN")
.anyRequest().authenticated()
.and().csrf().ignoringRequestMatchers("/api/**");
http.oauth2Login(withDefaults())
.logout()
.logoutUrl("/logout")
.addLogoutHandler(keycloakLogoutHandler)
.logoutRequestMatcher(new AntPathRequestMatcher("/logout", HttpMethod.GET.name()))
.logoutSuccessUrl("/");
return http.build();
}
Here is the debug:
2023-01-23T16:47:29.600 INFO 20700 --- [2)-172.22.34.73] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2023-01-23T16:47:29.600 INFO 20700 --- [2)-172.22.34.73] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2023-01-23T16:47:29.600 DEBUG 20700 --- [2)-172.22.34.73] o.s.web.servlet.DispatcherServlet : Detected StandardServletMultipartResolver
2023-01-23T16:47:29.600 DEBUG 20700 --- [2)-172.22.34.73] o.s.web.servlet.DispatcherServlet : Detected AcceptHeaderLocaleResolver
2023-01-23T16:47:29.600 DEBUG 20700 --- [2)-172.22.34.73] o.s.web.servlet.DispatcherServlet : Detected FixedThemeResolver
2023-01-23T16:47:29.601 DEBUG 20700 --- [2)-172.22.34.73] o.s.web.servlet.DispatcherServlet : Detected org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator#72c0080a
2023-01-23T16:47:29.601 DEBUG 20700 --- [2)-172.22.34.73] o.s.web.servlet.DispatcherServlet : Detected org.springframework.web.servlet.support.SessionFlashMapManager#7586194b
2023-01-23T16:47:29.601 DEBUG 20700 --- [2)-172.22.34.73] o.s.web.servlet.DispatcherServlet : enableLoggingRequestDetails='false': request parameters and headers will be masked to prevent unsafe logging of potentially sensitive data
2023-01-23T16:47:29.601 INFO 20700 --- [2)-172.22.34.73] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms
2023-01-23T16:47:32.136 DEBUG 20700 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to com.imsweb.seertransfer.controller.ApiController#processImport()
2023-01-23T16:47:32.138 DEBUG 20700 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to com.imsweb.seertransfer.controller.ApiController#processImport()
2023-01-23T16:47:32.145 DEBUG 20700 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#error(HttpServletRequest)
2023-01-23T16:47:32.147 DEBUG 20700 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#error(HttpServletRequest)
However if I switch the requestMatchers to "/**":
#Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests()
.requestMatchers("/**").permitAll()
.requestMatchers(EndpointRequest.to(HealthEndpoint.class)).permitAll()
.requestMatchers("/actuator/*").hasAuthority("ADMIN")
.anyRequest().authenticated()
.and().csrf().ignoringRequestMatchers("/api/**");
http.oauth2Login(withDefaults())
.logout()
.logoutUrl("/logout")
.addLogoutHandler(keycloakLogoutHandler)
.logoutRequestMatcher(new AntPathRequestMatcher("/logout", HttpMethod.GET.name()))
.logoutSuccessUrl("/");
return http.build();
}
I now get the correct results back:
{
"timestamp": "2023-01-23T21:55:39.115Z",
"status": 401,
"error": "Unauthorized",
"message": "You must supply an access token",
"path": "/api/import"
}
and the log looks different:
2023-01-23T16:48:47.791 INFO 10824 --- [2)-172.22.34.73] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2023-01-23T16:48:47.792 INFO 10824 --- [2)-172.22.34.73] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2023-01-23T16:48:47.792 DEBUG 10824 --- [2)-172.22.34.73] o.s.web.servlet.DispatcherServlet : Detected StandardServletMultipartResolver
2023-01-23T16:48:47.792 DEBUG 10824 --- [2)-172.22.34.73] o.s.web.servlet.DispatcherServlet : Detected AcceptHeaderLocaleResolver
2023-01-23T16:48:47.792 DEBUG 10824 --- [2)-172.22.34.73] o.s.web.servlet.DispatcherServlet : Detected FixedThemeResolver
2023-01-23T16:48:47.793 DEBUG 10824 --- [2)-172.22.34.73] o.s.web.servlet.DispatcherServlet : Detected org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator#1910b7
2023-01-23T16:48:47.793 DEBUG 10824 --- [2)-172.22.34.73] o.s.web.servlet.DispatcherServlet : Detected org.springframework.web.servlet.support.SessionFlashMapManager#6ee194ac
2023-01-23T16:48:47.793 DEBUG 10824 --- [2)-172.22.34.73] o.s.web.servlet.DispatcherServlet : enableLoggingRequestDetails='false': request parameters and headers will be masked to prevent unsafe logging of potentially sensitive data
2023-01-23T16:48:47.793 INFO 10824 --- [2)-172.22.34.73] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms
2023-01-23T16:48:51.362 DEBUG 10824 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to com.imsweb.seertransfer.controller.ApiController#processImport()
2023-01-23T16:48:51.365 DEBUG 10824 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to com.imsweb.seertransfer.controller.ApiController#processImport()
2023-01-23T16:48:51.372 DEBUG 10824 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#error(HttpServletRequest)
2023-01-23T16:48:51.374 DEBUG 10824 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : "ERROR" dispatch for POST "/error", parameters={}
2023-01-23T16:48:51.376 DEBUG 10824 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#error(HttpServletRequest)
2023-01-23T16:48:51.388 DEBUG 10824 --- [nio-8080-exec-1] o.s.w.s.m.m.a.HttpEntityMethodProcessor : Using 'application/json', given [application/json] and supported [application/json, application/*+json]
2023-01-23T16:48:51.389 DEBUG 10824 --- [nio-8080-exec-1] o.s.w.s.m.m.a.HttpEntityMethodProcessor : Writing [{timestamp=Mon Jan 23 16:48:51 EST 2023, status=401, error=Unauthorized, message=You must supply an (truncated)...]
2023-01-23T16:48:51.399 DEBUG 10824 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Exiting from "ERROR" dispatch, status 401
Is there something different that needs to be done with the matchers?
Create two separate SecurityFilterChain beans: one for REST configuration and one for the default configuration. Use http.securityMatcher(...) before authorizeHttpRequests() so that the REST filter chain only handles requests to API endpoints. In addition, ensure that the /error path is publicly accessible as it handles returning the JSON for errors.
#Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.oauth2Login(Customizer.withDefaults()).logout().logoutUrl("/logout")
.addLogoutHandler(keycloakLogoutHandler)
.logoutRequestMatcher(new AntPathRequestMatcher("/logout", HttpMethod.GET.name()))
.logoutSuccessUrl("/");
http.authorizeHttpRequests().requestMatchers("/error").permitAll().anyRequest().authenticated();
return http.build();
}
#Bean
#Order(1)
public SecurityFilterChain restSecurityFilterChain(HttpSecurity http) throws Exception {
http.securityMatcher("/api/**", "/actuator/*").authorizeHttpRequests().requestMatchers("/api/**").permitAll().requestMatchers("/actuator/*")
.hasAuthority("ADMIN").and().csrf().ignoringRequestMatchers("/api/**");
return http.build();
}
In my case, I was having every endpoint be authenticated except "/api/**". The problem turned out that when there is an error, the call is forwarded to "/error" even though it is only going to return JSON.
My solution was to change
.requestMatchers("/api/**").permitAll()
to
.requestMatchers("/api/**", "/error").permitAll()
Now the REST API is accessible and returns correct JSON errors, while the rest of the application is still authenticated. It seems strange to have to have the error page outside of auth, but it does work.

How do I debug a request in Spring Boot?

My computer restarted and my app no longer works today. It was working yesterday. Nothing changed except Maven downloading new libraries (mostly Amazon). Now I can't even access the /admin/login page. How do I debug the request?
2019-09-13 17:26:16.924 INFO 2056 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/admin/login],methods=[GET]}" onto public java.lang.String com.s.s.controller.Controller.login()
2019-09-13 17:26:21.465 ERROR 2056 --- [nio-8080-exec-1] c.s.s.c.Controller : invalidRequest(): invalid request: /admin/login
#RequestMapping(value="/admin/login", method=RequestMethod.GET)
public String login() {
return "login";
}
#RequestMapping("/error")
public void invalidRequest(HttpServletRequest request, HttpServletResponse response){
Logger.error(TAG, "invalidRequest()", "invalid request: " + request.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI));
try {
response.setStatus(HttpStatus.OK.value());
response.getWriter().write("This is not a valid request");
} catch (IOException e) {
Logger.error(TAG, "invalidRequest: ", "Exception in invalidRequest() method "+e.getMessage());
}
}
#Override
public String getErrorPath() {
return "/error";
}
I set this line in application.properties but it didn't print anything extra.
logging.level.com.s.s.controller.Controller=DEBUG
I ran mvn clean and restarted server, but it didn't help.
I set this line in application.properties but it didn't print anything useful.
debug=true
Log:
2019-09-13 17:40:25.459 DEBUG 2056 --- [nio-8080-exec-1] o.s.b.w.f.OrderedRequestContextFilter : Bound request context to thread: org.apache.catalina.connector.RequestFacade#4d3e8c3a
2019-09-13 17:40:25.460 DEBUG 2056 --- [nio-8080-exec-1] o.s.b.w.f.OrderedRequestContextFilter : Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade#4d3e8c3a
2019-09-13 17:40:25.463 ERROR 2056 --- [nio-8080-exec-1] c.s.s.c.Controller : invalidRequest(): invalid request: /admin/login
2019-09-13 17:40:25.477 DEBUG 2056 --- [nio-8080-exec-2] o.s.b.w.f.OrderedRequestContextFilter : Bound request context to thread: org.apache.catalina.connector.RequestFacade#4d3e8c3a
2019-09-13 17:40:25.484 DEBUG 2056 --- [nio-8080-exec-2] o.s.b.w.f.OrderedRequestContextFilter : Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade#4d3e8c3a
$ git status
modified: src/main/resources/application.properties
modified: src/main/resources/static/js/home.js
I compared libraries to what was last deployed and the only changes were
aws-java-sdk-core-1.11.631.jar
aws-java-sdk-kms-1.11.631.jar
aws-java-sdk-s3-1.11.631.jar
aws-java-sdk-ses-1.11.631.jar
jmespath-java-1.11.631.jar
I commented public String getErrorPath() and public void invalidRequest() and now it gives me
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Fri Sep 13 18:59:03 UTC 2019
There was an unexpected error (type=Forbidden, status=403).
No message available
But with curl it gives
$ curl localhost:8080/admin/login
{"timestamp":1568401131164,"status":403,"error":"Forbidden","message":"No message available","path":"/admin/login"}
I found the following searching for spring-sleuth in Makgigrahul's answer and added it to application.properties producing this log.
logging.level.org.springframework.web.servlet.DispatcherServlet=DEBUG
Log:
2019-09-13 16:10:11.329 DEBUG 15356 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing servlet 'dispatcherServlet'
2019-09-13 16:10:11.330 INFO 15356 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2019-09-13 16:10:11.331 INFO 15356 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2019-09-13 16:10:11.332 DEBUG 15356 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Using MultipartResolver [org.springframework.web.multipart.support.StandardServletMultipartResolver#6481dcd8]
2019-09-13 16:10:11.332 DEBUG 15356 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Using LocaleResolver [org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver#50cc90f2]
2019-09-13 16:10:11.339 DEBUG 15356 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Unable to locate ThemeResolver with name 'themeResolver': using default [org.springframework.web.servlet.theme.FixedThemeResolver#135fd762]
2019-09-13 16:10:11.345 DEBUG 15356 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Unable to locate RequestToViewNameTranslator with name 'viewNameTranslator': using default [org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator#61cc4a6b]
2019-09-13 16:10:11.352 DEBUG 15356 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Unable to locate FlashMapManager with name 'flashMapManager': using default [org.springframework.web.servlet.support.SessionFlashMapManager#766c1f26]
2019-09-13 16:10:11.353 DEBUG 15356 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Published WebApplicationContext of servlet 'dispatcherServlet' as ServletContext attribute with name [org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcherServlet]
2019-09-13 16:10:11.355 INFO 15356 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 23 ms
2019-09-13 16:10:11.356 DEBUG 15356 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Servlet 'dispatcherServlet' configured successfully
2019-09-13 16:10:11.376 DEBUG 15356 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/error]
2019-09-13 16:10:11.383 DEBUG 15356 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Last-Modified value for [/error] is: -1
2019-09-13 16:10:11.408 DEBUG 15356 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Rendering view [org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$SpelView#53191939] in DispatcherServlet with name 'dispatcherServlet'
2019-09-13 16:10:11.415 DEBUG 15356 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Successfully completed request
You can try to set a breakpoint in org.apache.catalina.core.ApplicationFilterChain#doFilter. Thats pretty at the beginning of the request processing. Or you can have a look in org.springframework.web.servlet.DispatcherServlet#doDispatch
I was able to debug using Andreas' answer and saw the values for request.request.filterChain.filters[] and saw my filter remoteAddressFilter() and saw remoteAddress = 0:0:0:0:0:0:0:1. I have an IP filter (RemoteAddrFilter) and one of the allowed values is 127.0.0.1. I was accessing the server with http://localhost:8080/admin/home, which apparently uses the IP6 address. Probably a Windows update which restarted the computer changed the networking behavior. When I use http://127.0.0.1:8080/admin/home it works. I would like to add logging to the filter to notify when blocked, but there is no apparent way. Amazing Spring doesn't log the filters in debug mode.

SpringBoot Web MVC Application Cannot resolve view

I have been using Spring Boot ReST APIs for quite some time; I thought of experimenting with web-MVC. However, I have got stuck on the first part itself.
I have uploaded the project on GitHub
What I have done so far:
Defined POM.xml with spring-boot-starter-web + tomcat-embed-jasper mainly.
Defined a #Controller with #GetMapping("/greeting"), which returns the name of a view - hello
Defined following properties:
spring.mvc.view.prefix=/WEB-INF/views/
spring.mvc.view.suffix=.jsp
Created a very basic view hello.jsp at src/main/web/WEB-INF/views/hello.jsp
Created a main Application to run as SpringBootApplication.
Error:
Whitelabel Error Page
This application has no explicit mapping for
/error, so you are seeing this as a fallback.
Mon Mar 26 22:55:03 IST 2018
There was an unexpected error (type=Not Found, status=404). No message available
Logs:
2018-03-26 22:55:02.998 DEBUG 7132 --- [nio-8080-exec-1] o.a.coyote.http11.Http11InputBuffer : Received [GET /greeting HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
DNT: 1
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,hi;q=0.8
]
2018-03-26 22:55:03.043 DEBUG 7132 --- [nio-8080-exec-1] org.apache.tomcat.util.http.Parameters : Set query string encoding to UTF-8
2018-03-26 22:55:03.054 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.authenticator.AuthenticatorBase : Security checking request GET /greeting
2018-03-26 22:55:03.054 DEBUG 7132 --- [nio-8080-exec-1] org.apache.catalina.realm.RealmBase : No applicable constraints defined
2018-03-26 22:55:03.063 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.a.jaspic.AuthConfigFactoryImpl : Loading persistent provider registrations from [C:\Users\NirMit\AppData\Local\Temp\tomcat.3836668232954126555.8080\conf\jaspic-providers.xml]
2018-03-26 22:55:03.064 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.authenticator.AuthenticatorBase : Not subject to any constraint
2018-03-26 22:55:03.067 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing servlet 'dispatcherServlet'
2018-03-26 22:55:03.068 INFO 7132 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2018-03-26 22:55:03.069 INFO 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2018-03-26 22:55:03.069 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'multipartResolver'
2018-03-26 22:55:03.069 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Using MultipartResolver [org.springframework.web.multipart.support.StandardServletMultipartResolver#a8d0be]
2018-03-26 22:55:03.070 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Creating instance of bean 'org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver'
2018-03-26 22:55:03.074 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase : findClass(java.lang.ObjectCustomizer)
2018-03-26 22:55:03.074 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase : --> Returning ClassNotFoundException
2018-03-26 22:55:03.077 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase : findClass(org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolverCustomizer)
2018-03-26 22:55:03.079 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase : --> Returning ClassNotFoundException
2018-03-26 22:55:03.082 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase : findClass(org.springframework.web.servlet.LocaleResolverCustomizer)
2018-03-26 22:55:03.084 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase : --> Returning ClassNotFoundException
2018-03-26 22:55:03.084 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Finished creating instance of bean 'org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver'
2018-03-26 22:55:03.085 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Unable to locate LocaleResolver with name 'localeResolver': using default [org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver#1c2a3a2]
2018-03-26 22:55:03.086 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Creating instance of bean 'org.springframework.web.servlet.theme.FixedThemeResolver'
2018-03-26 22:55:03.091 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase : findClass(java.lang.ObjectCustomizer)
2018-03-26 22:55:03.091 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase : --> Returning ClassNotFoundException
2018-03-26 22:55:03.093 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase : findClass(org.springframework.web.servlet.theme.AbstractThemeResolverCustomizer)
2018-03-26 22:55:03.095 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase : --> Returning ClassNotFoundException
2018-03-26 22:55:03.097 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase : findClass(org.springframework.web.servlet.theme.FixedThemeResolverCustomizer)
2018-03-26 22:55:03.098 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase : --> Returning ClassNotFoundException
2018-03-26 22:55:03.101 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase : findClass(org.springframework.web.servlet.ThemeResolverCustomizer)
2018-03-26 22:55:03.108 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase : --> Returning ClassNotFoundException
2018-03-26 22:55:03.109 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Finished creating instance of bean 'org.springframework.web.servlet.theme.FixedThemeResolver'
2018-03-26 22:55:03.115 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Unable to locate ThemeResolver with name 'themeResolver': using default [org.springframework.web.servlet.theme.FixedThemeResolver#1855c21]
2018-03-26 22:55:03.116 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'requestMappingHandlerMapping'
2018-03-26 22:55:03.116 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'viewControllerHandlerMapping'
2018-03-26 22:55:03.116 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'beanNameHandlerMapping'
2018-03-26 22:55:03.116 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'resourceHandlerMapping'
2018-03-26 22:55:03.116 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'defaultServletHandlerMapping'
2018-03-26 22:55:03.116 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'faviconHandlerMapping'
2018-03-26 22:55:03.116 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'welcomePageHandlerMapping'
2018-03-26 22:55:03.117 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'requestMappingHandlerAdapter'
2018-03-26 22:55:03.117 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'httpRequestHandlerAdapter'
2018-03-26 22:55:03.117 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'simpleControllerHandlerAdapter'
2018-03-26 22:55:03.117 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'errorAttributes'
2018-03-26 22:55:03.117 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'handlerExceptionResolver'
2018-03-26 22:55:03.121 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Creating instance of bean 'org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator'
2018-03-26 22:55:03.124 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase : findClass(java.lang.ObjectCustomizer)
2018-03-26 22:55:03.124 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase : --> Returning ClassNotFoundException
2018-03-26 22:55:03.126 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase : findClass(org.springframework.web.servlet.view.DefaultRequestToViewNameTranslatorCustomizer)
2018-03-26 22:55:03.128 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase : --> Returning ClassNotFoundException
2018-03-26 22:55:03.130 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase : findClass(org.springframework.web.servlet.RequestToViewNameTranslatorCustomizer)
2018-03-26 22:55:03.132 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase : --> Returning ClassNotFoundException
2018-03-26 22:55:03.133 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Finished creating instance of bean 'org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator'
2018-03-26 22:55:03.133 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Unable to locate RequestToViewNameTranslator with name 'viewNameTranslator': using default [org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator#99d4c6]
2018-03-26 22:55:03.133 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'beanNameViewResolver'
2018-03-26 22:55:03.134 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'mvcViewResolver'
2018-03-26 22:55:03.134 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'defaultViewResolver'
2018-03-26 22:55:03.134 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'viewResolver'
2018-03-26 22:55:03.137 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Creating instance of bean 'org.springframework.web.servlet.support.SessionFlashMapManager'
2018-03-26 22:55:03.141 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase : findClass(java.lang.ObjectCustomizer)
2018-03-26 22:55:03.142 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase : --> Returning ClassNotFoundException
2018-03-26 22:55:03.143 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase : findClass(org.springframework.web.servlet.support.AbstractFlashMapManagerCustomizer)
2018-03-26 22:55:03.146 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase : --> Returning ClassNotFoundException
2018-03-26 22:55:03.153 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase : findClass(org.springframework.web.servlet.support.SessionFlashMapManagerCustomizer)
2018-03-26 22:55:03.156 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase : --> Returning ClassNotFoundException
2018-03-26 22:55:03.158 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase : findClass(org.springframework.web.servlet.FlashMapManagerCustomizer)
2018-03-26 22:55:03.160 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.loader.WebappClassLoaderBase : --> Returning ClassNotFoundException
2018-03-26 22:55:03.161 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Finished creating instance of bean 'org.springframework.web.servlet.support.SessionFlashMapManager'
2018-03-26 22:55:03.161 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Unable to locate FlashMapManager with name 'flashMapManager': using default [org.springframework.web.servlet.support.SessionFlashMapManager#3d023d]
2018-03-26 22:55:03.161 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Published WebApplicationContext of servlet 'dispatcherServlet' as ServletContext attribute with name [org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcherServlet]
2018-03-26 22:55:03.161 INFO 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 92 ms
2018-03-26 22:55:03.161 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Servlet 'dispatcherServlet' configured successfully
2018-03-26 22:55:03.177 DEBUG 7132 --- [169.254.165.176] sun.rmi.transport.tcp : RMI TCP Connection(3)-169.254.165.176: (port 51150) connection closed
2018-03-26 22:55:03.177 DEBUG 7132 --- [169.254.165.176] sun.rmi.transport.tcp : RMI TCP Connection(3)-169.254.165.176: close connection
2018-03-26 22:55:03.200 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.w.s.f.OrderedRequestContextFilter : Bound request context to thread: org.apache.catalina.connector.RequestFacade#1cc2c8
2018-03-26 22:55:03.211 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/greeting]
2018-03-26 22:55:03.217 DEBUG 7132 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /greeting
2018-03-26 22:55:03.223 DEBUG 7132 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method [public java.lang.String com.khandhedia.sprinboot.mvc.demo1.controller.GreetingController.greetingForm(org.springframework.ui.Model)]
2018-03-26 22:55:03.223 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'greetingController'
2018-03-26 22:55:03.224 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Last-Modified value for [/greeting] is: -1
2018-03-26 22:55:03.285 DEBUG 7132 --- [nio-8080-exec-1] o.s.w.s.v.ContentNegotiatingViewResolver : Requested media types are [text/html, application/xhtml+xml, image/webp, image/apng, application/xml;q=0.9, */*;q=0.8] based on Accept header types and producible media types [*/*])
2018-03-26 22:55:03.285 DEBUG 7132 --- [nio-8080-exec-1] o.s.w.servlet.view.BeanNameViewResolver : No matching bean found for view name 'hello'
2018-03-26 22:55:03.293 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Invoking afterPropertiesSet() on bean with name 'hello'
2018-03-26 22:55:03.295 DEBUG 7132 --- [nio-8080-exec-1] o.s.w.s.v.ContentNegotiatingViewResolver : Returning [org.springframework.web.servlet.view.JstlView: name 'hello'; URL [/WEB-INF/views/hello.jsp]] based on requested media type 'text/html'
2018-03-26 22:55:03.295 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Rendering view [org.springframework.web.servlet.view.JstlView: name 'hello'; URL [/WEB-INF/views/hello.jsp]] in DispatcherServlet with name 'dispatcherServlet'
2018-03-26 22:55:03.296 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.view.JstlView : Added model object 'name' of type [java.lang.String] to request in view with name 'hello'
2018-03-26 22:55:03.307 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.view.JstlView : Forwarding to resource [/WEB-INF/views/hello.jsp] in InternalResourceView 'hello'
2018-03-26 22:55:03.318 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/WEB-INF/views/hello.jsp]
2018-03-26 22:55:03.318 DEBUG 7132 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /WEB-INF/views/hello.jsp
2018-03-26 22:55:03.340 DEBUG 7132 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Did not find handler method for [/WEB-INF/views/hello.jsp]
2018-03-26 22:55:03.340 DEBUG 7132 --- [nio-8080-exec-1] o.s.w.s.handler.SimpleUrlHandlerMapping : Matching patterns for request [/WEB-INF/views/hello.jsp] are [/**]
2018-03-26 22:55:03.342 DEBUG 7132 --- [nio-8080-exec-1] o.s.w.s.handler.SimpleUrlHandlerMapping : URI Template variables for request [/WEB-INF/views/hello.jsp] are {}
2018-03-26 22:55:03.343 DEBUG 7132 --- [nio-8080-exec-1] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapping [/WEB-INF/views/hello.jsp] to HandlerExecutionChain with handler [ResourceHttpRequestHandler [locations=[class path resource [META-INF/resources/], class path resource [resources/], class path resource [static/], class path resource [public/], ServletContext resource [/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver#1113a37]]] and 1 interceptor
2018-03-26 22:55:03.344 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Last-Modified value for [/WEB-INF/views/hello.jsp] is: -1
2018-03-26 22:55:03.344 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
2018-03-26 22:55:03.344 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Successfully completed request
2018-03-26 22:55:03.347 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Disabling the response for further output
2018-03-26 22:55:03.347 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Successfully completed request
2018-03-26 22:55:03.347 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.w.s.f.OrderedRequestContextFilter : Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade#1cc2c8
2018-03-26 22:55:03.348 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost] : Processing ErrorPage[errorCode=0, location=/error]
2018-03-26 22:55:03.349 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/error]
2018-03-26 22:55:03.350 DEBUG 7132 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /error
2018-03-26 22:55:03.351 DEBUG 7132 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method [public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)]
2018-03-26 22:55:03.351 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'basicErrorController'
2018-03-26 22:55:03.352 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Last-Modified value for [/error] is: -1
2018-03-26 22:55:03.354 DEBUG 7132 --- [nio-8080-exec-1] o.s.c.e.PropertySourcesPropertyResolver : Could not find key 'spring.template.provider.cache' in any property source
2018-03-26 22:55:03.358 DEBUG 7132 --- [nio-8080-exec-1] o.s.c.e.PropertySourcesPropertyResolver : Could not find key 'spring.template.provider.cache' in any property source
2018-03-26 22:55:03.383 DEBUG 7132 --- [nio-8080-exec-1] o.s.w.s.v.ContentNegotiatingViewResolver : Requested media types are [text/html, text/html;q=0.8] based on Accept header types and producible media types [text/html])
2018-03-26 22:55:03.383 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'error'
2018-03-26 22:55:03.383 DEBUG 7132 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Invoking afterPropertiesSet() on bean with name 'error'
2018-03-26 22:55:03.383 DEBUG 7132 --- [nio-8080-exec-1] o.s.w.s.v.ContentNegotiatingViewResolver : Returning [org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$SpelView#1943f03] based on requested media type 'text/html'
2018-03-26 22:55:03.383 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Rendering view [org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$SpelView#1943f03] in DispatcherServlet with name 'dispatcherServlet'
2018-03-26 22:55:03.420 DEBUG 7132 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Successfully completed request
2018-03-26 22:55:03.420 DEBUG 7132 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Disabling the response for further output
2018-03-26 22:55:03.439 DEBUG 7132 --- [nio-8080-exec-1] o.a.tomcat.util.net.SocketWrapperBase : Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper#10910ae:org.apache.tomcat.util.net.NioChannel#4cbd6d:java.nio.channels.SocketChannel[connected local=/0:0:0:0:0:0:0:1:8080 remote=/0:0:0:0:0:0:0:1:51167]], Read from buffer: [0]
2018-03-26 22:55:03.440 DEBUG 7132 --- [nio-8080-exec-1] o.apache.coyote.http11.Http11Processor : Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper#10910ae:org.apache.tomcat.util.net.NioChannel#4cbd6d:java.nio.channels.SocketChannel[connected local=/0:0:0:0:0:0:0:1:8080 remote=/0:0:0:0:0:0:0:1:51167]], Status in: [OPEN_READ], State out: [OPEN]
2018-03-26 22:55:09.322 DEBUG 7132 --- [nio-8080-exec-5] o.a.tomcat.util.net.SocketWrapperBase : Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper#10910ae:org.apache.tomcat.util.net.NioChannel#4cbd6d:java.nio.channels.SocketChannel[connected local=/0:0:0:0:0:0:0:1:8080 remote=/0:0:0:0:0:0:0:1:51167]], Read from buffer: [0]
2018-03-26 22:55:09.322 DEBUG 7132 --- [nio-8080-exec-5] o.apache.coyote.http11.Http11Processor : Error parsing HTTP request header
EDIT:
I tried following changes as per the comments; however, it doesn't seem to help yet.
Putting hello.jsp in src/main/resources/templates/WEB-INF/views
Putting hello.jsp in src/main/resources/static/WEB-INF/views
Putting hello.jsp in src/main/resources/WEB-INF/views
Putting hello.jsp in src/main/webapp/WEB-INF/views
Please advise.
The issue was with the provided scope of Maven Dependency tomcat-embed-jasper which is used to compile the JSPs.
With default scope for this maven dependency, it flies!
<!-- Tomcat for JSP rendering -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
Two cents from my analysis!
What is the use of this dependency when we already have spring-boot-starter-web?
The spring-boot-starter-web includes the spring-boot-starter-tomcat and the spring-boot-starter-tomcat includes the tomcat-embed-core.
But, tomcat-embed-core doesn't include tomcat-embed-jasper.
Now, according to maven docs, if the tomcat-embed-jasper is marked as provided, it means that it expects the JDK or a container to provide the dependency at runtime.
This scope is only available on the compilation and test classpath, and is not transitive.
Hence, effectively this dependency is not available when JSPs are being compiled.
By marking this dependency scope as compile, it is made available in all the classpaths and to all the dependent projects as well.
Summary: The spring-boot-starter-web has tomcat embedded dependency but it doesn't include the jasper embedded dependency. One needs to add this dependency with default compile scope.
Where to place the JSPs/View Components in a Spring Boot Project?
Create a Web Project using Spring Inializr or IntelliJ Spring Plugins.
Add Web framework support using IDE. It may create a directory as src/main/web/WEB-INF
Rename the directory from web to webapp
Create the view components like JSPs at src/main/webapp/WEB-INF/views/
Define following properties in application.properties
spring.mvc.view.prefix=/WEB-INF/views/
spring.mvc.view.suffix=.jsp
src/main/web/WEB-INF/views/hello.jsp
will not be found by Spring Boot. As a Spring Boot convention you should put your views under resources folder:
src/main/resources/templates/...
And for your CSS:
src/main/resources/static/...
And if you are using Spring Boot, then it's a good idea to use the project initializer:
https://start.spring.io/
from there choose what view technology you want, and Spring Boot will add its dependencies for you, so you don't need to add them or configure them yourself(step 3).

Resolving exception from handler and Request method 'PUT' not supported

I just can not. For 4 days I have been struggling to send data ajax using a different method than GET and I can not advise. I create a project in Spring Boot. I have created a mapped address controller
#PutMapping(value = "/changeEmail", consumes = MediaType.APPLICATION_JSON_VALUE)
public boolean changeEmail(
#RequestBody ChangeEmailDTO changeEmailDTO
) {
System.out.println("email: " + changeEmailDTO.getEmail());
return true;
}
This controller is supposed to accept the email address sent by ajaxa
function changeEmail() {
console.log("Event");
$.ajax({
type: 'PUT',
url: '/changeEmail',
data: {
email: JSON.strgify($('#email').val())
},
success: function (result) {
console.log('function');
}
});
}
However, the only effect is that in the console crashes me
PUT http://localhost:8080/signIn net::ERR_TOO_MANY_REDIRECTS
send # jquery-3.2.1.min.js:4
ajax # jquery-3.2.1.min.js:4
changeEmail # settings.js:58
submitHandler # settings.js:52
d # jquery.validate.min.js:4
(anonymous) # jquery.validate.min.js:4
dispatch # jquery-3.2.1.min.js:3
q.handle # jquery-3.2.1.min.js:3
The DTO has only one field
public class ChangeEmailDTO {
#IsValidEmail
#ExistsEmail(ifExistsReturn = false)
#Getter #Setter private String email;
}
After trying to send data via ajax, it sends me to the error controller
#Controller
public class PageNotFoundController implements ErrorController{
#RequestMapping("/error")
public ModelAndView showPageError() {
return new ModelAndView("redirect:/signIn");
}
#Override
public String getErrorPath() {
return "/error";
}
}
Screen with browser tool what to send and receive: https://zapodaj.net/f1b8ed0b2a16b.png.html
As I mentioned, the controller can correctly pick up a GET query from ajax only. Every time it flips on the error controller.
Additionally, they say that if I wanted to send data directly from the form, then there is no problem with any query.
What this ajax divert, I do not know.
In addition, when the csrf() is disabled in Spring Security receives such logs
2017-07-26 21:07:15.465 DEBUG 3760 --- [nio-8080-exec-6] o.s.web.servlet.DispatcherServlet : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
2017-07-26 21:07:15.465 DEBUG 3760 --- [nio-8080-exec-6] o.s.web.servlet.DispatcherServlet : Successfully completed request
2017-07-26 21:07:15.499 DEBUG 3760 --- [nio-8080-exec-7] o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing PUT request for [/changeEmail]
2017-07-26 21:07:15.501 DEBUG 3760 --- [nio-8080-exec-7] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /changeEmail
2017-07-26 21:07:15.505 DEBUG 3760 --- [nio-8080-exec-7] .m.m.a.ExceptionHandlerExceptionResolver : Resolving exception from handler [null]: org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
2017-07-26 21:07:15.506 DEBUG 3760 --- [nio-8080-exec-7] .w.s.m.a.ResponseStatusExceptionResolver : Resolving exception from handler [null]: org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
2017-07-26 21:07:15.506 DEBUG 3760 --- [nio-8080-exec-7] .w.s.m.s.DefaultHandlerExceptionResolver : Resolving exception from handler [null]: org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
2017-07-26 21:07:15.508 DEBUG 3760 --- [nio-8080-exec-7] o.s.web.servlet.DispatcherServlet : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
2017-07-26 21:07:15.508 DEBUG 3760 --- [nio-8080-exec-7] o.s.web.servlet.DispatcherServlet : Successfully completed request
2017-07-26 21:07:15.509 DEBUG 3760 --- [nio-8080-exec-7] o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing PUT request for [/error]
2017-07-26 21:07:15.510 DEBUG 3760 --- [nio-8080-exec-7] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /error
2017-07-26 21:07:15.511 DEBUG 3760 --- [nio-8080-exec-7] s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method [public org.springframework.web.servlet.ModelAndView com.movie.database.app.controller.error.PageNotFoundController.showPageError()]
2017-07-26 21:07:15.526 DEBUG 3760 --- [nio-8080-exec-7] o.s.web.cors.DefaultCorsProcessor : Skip CORS processing: request is from same origin
here
2017-07-26 21:07:15.527 DEBUG 3760 --- [nio-8080-exec-7] o.s.w.s.v.ContentNegotiatingViewResolver : Requested media types are [*/*] based on Accept header types and producible media types [*/*])
2017-07-26 21:07:15.528 DEBUG 3760 --- [nio-8080-exec-7] o.s.w.servlet.view.BeanNameViewResolver : No matching bean found for view name 'redirect:/signIn'
2017-07-26 21:07:15.528 DEBUG 3760 --- [nio-8080-exec-7] o.s.w.s.v.ContentNegotiatingViewResolver : Returning redirect view [org.springframework.web.servlet.view.RedirectView: unnamed; URL [/signIn]]
2017-07-26 21:07:15.528 DEBUG 3760 --- [nio-8080-exec-7] o.s.web.servlet.DispatcherServlet : Rendering view [org.springframework.web.servlet.view.RedirectView: unnamed; URL [/signIn]] in DispatcherServlet with name 'dispatcherServlet'
2017-07-26 21:07:15.530 DEBUG 3760 --- [nio-8080-exec-7] o.s.web.servlet.DispatcherServlet : Successfully completed request
2017-07-26 21:07:15.534 DEBUG 3760 --- [nio-8080-exec-9] o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing PUT request for [/signIn]
2017-07-26 21:07:15.535 DEBUG 3760 --- [nio-8080-exec-9] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /signIn
2017-07-26 21:07:15.536 DEBUG 3760 --- [nio-8080-exec-9] .m.m.a.ExceptionHandlerExceptionResolver : Resolving exception from handler [null]: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'PUT' not supported
2017-07-26 21:07:15.536 DEBUG 3760 --- [nio-8080-exec-9] .w.s.m.a.ResponseStatusExceptionResolver : Resolving exception from handler [null]: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'PUT' not supported
2017-07-26 21:07:15.536 DEBUG 3760 --- [nio-8080-exec-9] .w.s.m.s.DefaultHandlerExceptionResolver : Resolving exception from handler [null]: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'PUT' not supported
2017-07-26 21:07:15.536 WARN 3760 --- [nio-8080-exec-9] o.s.web.servlet.PageNotFound : Request method 'PUT' not supported
2017-07-26 21:07:15.536 DEBUG 3760 --- [nio-8080-exec-9] o.s.web.servlet.DispatcherServlet : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
2017-07-26 21:07:15.536 DEBUG 3760 --- [nio-8080-exec-9] o.s.web.servlet.DispatcherServlet : Successfully completed request
2017-07-26 21:07:15.537 DEBUG 3760 --- [nio-8080-exec-9] o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing PUT request for [/error]
2017-07-26 21:07:15.538 DEBUG 3760 --- [nio-8080-exec-9] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /error
2017-07-26 21:07:15.539 DEBUG 3760 --- [nio-8080-exec-9] s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method [public org.springframework.web.servlet.ModelAndView com.movie.database.app.controller.error.PageNotFoundController.showPageError()]
2017-07-26 21:07:15.539 DEBUG 3760 --- [nio-8080-exec-9] o.s.web.cors.DefaultCorsProcessor : Skip CORS processing: request is from same origin
The most important mistakes are
2017-07-26 21:07:15.506 DEBUG 3760 --- [nio-8080-exec-7] .w.s.m.s.DefaultHandlerExceptionResolver : Resolving exception from handler [null]: org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
2017-07-26 21:07:15.536 DEBUG 3760 --- [nio-8080-exec-9] .m.m.a.ExceptionHandlerExceptionResolver : Resolving exception from handler [null]: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'PUT' not supported
2017-07-26 21:07:15.536 WARN 3760 --- [nio-8080-exec-9] o.s.web.servlet.PageNotFound : Request method 'PUT' not supported
Your error message tells you your issue: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
Add contentType: 'application/json; charset=utf-8', to your ajax call. You'll also want to call JSON.stringify on the entire JSON string. Check out the w3schools page on stringify for a good example, also copied/pasted below.
var obj = { "name":"John", "age":30, "city":"New York"};
var myJSON = JSON.stringify(obj);

How to configure Bean for rssView with annotation in spring

I want to add rss source for my site in spring and the final step is configure the Bean of CustomRssView.
but tutorial used xml to configure it. I hope to use #Bean annotation. However, It's failed to resolve the view name.
xml in tutorial
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.mkyong.common.controller" />
<!-- Map returned view name "rssViewer" to bean id "rssViewer" -->
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />
<bean id="rssViewer" class="com.mkyong.common.rss.CustomRssViewer" />
my bean configuration
#SpringBootApplication
public class Application {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(Application.class, args);
System.out.println("Let's inspect the beans provided by Spring Boot:");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
}
#Bean
public RssView rssView() {
return new RssView();
}
}
It is successful to register, but the view name is not resolved by BeanNameViewResolver.
some debug info
2015-09-08 16:02:13.103 TRACE 21367 --- [nio-8080-exec-1] .w.s.m.m.a.ServletInvocableHandlerMethod : Method [getRssFeed] returned [ModelAndView: reference to view with name 'rssView'; model is {rss=[Post(id=0, menuId=0, submenuId=0, date=null, author=admin, title=Spring MVC Tutorial 1, content=Tutorial 1 Content ...), Post(id=0, menuId=0, submenuId=0, date=null, author=system, title=Spring MVC Tutorial 2, content=Tutorial 2 Content ...)]}]
2015-09-08 16:02:13.103 TRACE 21367 --- [nio-8080-exec-1] HandlerMethodReturnValueHandlerComposite : Testing if return value handler [org.springframework.web.servlet.mvc.method.annotation.ModelAndViewMethodReturnValueHandler#46a550ec] supports [class org.springframework.web.servlet.ModelAndView]
2015-09-08 16:02:13.111 DEBUG 21367 --- [nio-8080-exec-1] o.s.w.s.v.ContentNegotiatingViewResolver : Requested media types are [text/html, application/xhtml+xml, image/webp, application/xml;q=0.9, */*;q=0.8] based on Accept header types and producible media types [*/*])
2015-09-08 16:02:13.111 DEBUG 21367 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'rssView'
2015-09-08 16:02:13.113 DEBUG 21367 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Invoking afterPropertiesSet() on bean with name 'rssView'
2015-09-08 16:02:13.113 DEBUG 21367 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'org.springframework.
2015-09-08 16:02:13.113 DEBUG 21367 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Invoking afterPropertiesSet() on bean with name 'rssView'
2015-09-08 16:02:13.113 DEBUG 21367 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
2015-09-08 16:02:13.113 TRACE 21367 --- [nio-8080-exec-1] o.s.w.s.v.InternalResourceViewResolver : Cached view [rssView]
2015-09-08 16:02:13.114 DEBUG 21367 --- [nio-8080-exec-1] o.s.w.s.v.ContentNegotiatingViewResolver : Returning [org.springframework.web.servlet.view.InternalResourceView: name 'rssView'; URL [rssView]] based on requested media type 'text/html'
2015-09-08 16:02:13.114 DEBUG 21367 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Rendering view [org.springframework.web.servlet.view.InternalResourceView: name 'rssView'; URL [rssView]] in DispatcherServlet with name 'dispatcherServlet'
2015-09-08 16:02:13.114 TRACE 21367 --- [nio-8080-exec-1] o.s.w.servlet.view.InternalResourceView : Rendering view with name 'rssView' with model {rss=[Post(id=0, menuId=0, submenuId=0, date=null, author=admin, title=Spring MVC Tutorial 1, content=Tutorial 1 Content ...), Post(id=0, menuId=0, submenuId=0, date=null, author=system, title=Spring MVC Tutorial 2, content=Tutorial 2 Content ...)]} and static attributes {}
2015-09-08 16:02:13.114 DEBUG 21367 --- [nio-8080-exec-1] o.s.w.servlet.view.InternalResourceView : Added model object 'rss' of type [java.util.ArrayList] to request in view with name 'rssView'
2015-09-08 16:02:13.116 DEBUG 21367 --- [nio-8080-exec-1] o.s.w.servlet.view.InternalResourceView : Forwarding to resource [rssView] in InternalResourceView 'rssView'
2015-09-08 16:02:13.125 TRACE 21367 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Bound request context to thread: org.apache.catalina.core.ApplicationHttpRequest#41e5804f
2015-09-08 16:02:13.125 DEBUG 21367 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet
how to change my code.

Categories