@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".jsp");
return resolver;
}
forward is MvcConfig.java. As you can see, i add resourcehandler for static resources.
private void addDispatcherServlet(ServletContext servletContext)
{
AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
applicationContext.getEnvironment().addActiveProfile("production");
applicationContext.register(MvcConfig.class);
ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(applicationContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
dispatcher.setInitParameter("dispatchOptionsRequest", "true");
}
private void addUtf8CharacterEncodingFilter(ServletContext servletContext)
{
FilterRegistration.Dynamic filter = servletContext.addFilter("CHARACTER_ENCODING_FILTER", CharacterEncodingFilter.class);
filter.setInitParameter("encoding", "UTF-8");
filter.setInitParameter("forceEncoding", "true");
filter.addMappingForUrlPatterns(null, false, "/*");
}
And there is Initializer.java
There is my resource hierachy.
src
-main
--java
--resources
--webapp
---WEB-INF
----resources
-----css
------ signin.css
----views
In index.jsp,I called signin.css like this.
<link href="/resources/css/signin.css" rel="stylesheet">
Then, i can found these error message.
WARN [2017-03-07 14:37:49] ({http-bio-8080-exec-14} DefaultHandlerExceptionResolver.java[handleHttpRequestMethodNotSupported]:215) - Request method 'GET' not supported
WARN [2017-03-07 14:37:49] ({http-bio-8080-exec-15} DefaultHandlerExceptionResolver.java[handleHttpRequestMethodNotSupported]:215) - Request method 'GET' not supported
In chrome browser, also has 405 error. [405-Error screen shot][1][1]: https://i.stack.imgur.com/vmDlk.png
How can i fix it?
src/main/resources/public
(orstatic
) and you don't have to configure any of the resolvers yourself. – chrylis 22 hours ago