首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring boot dispatcher

Spring boot dispatcher
EN

Stack Overflow用户
提问于 2018-04-16 16:45:29
回答 1查看 4.2K关注 0票数 0

大家好,我正在尝试配置Spring Boot,但是我遗漏了一些东西。我添加注释的Application.java是:

代码语言:javascript
复制
@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

我为jsp页面配置默认servlet处理和解析器的SpringConfig.java是:

代码语言:javascript
复制
@Configuration 
@EnableWebMvc 
@ComponentScan(basePackages = "com.spring")
public class SpringConfig extends WebMvcConfigurerAdapter {

     @Override
     public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
            configurer.enable();
        }

    @Bean
    public ViewResolver viewResolver() {
            InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setViewClass(JstlView.class);
        viewResolver.setPrefix("/WEB-INF/pages/");
        viewResolver.setSuffix(".jsp");
        return viewResolver;
    } 

}

和我的控制器:

代码语言:javascript
复制
@Controller
public class SpringController {

    @RequestMapping(value = "/index", method = RequestMethod.GET)
       public String index() {
          return "index";
       }
@RequestMapping(value = "/hello", method = RequestMethod.GET)
 public ModelAndView hello() {
  return new ModelAndView("hello").addObject("name", "Yashwant");
 }

当我调用http://localhost:8080/web/hello时,我有这样的日志:

代码语言:javascript
复制
2018-04-16 10:40:40.096 DEBUG 6860 --- [nio-8080-exec-6] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Looking up handler method for path /hello
2018-04-16 10:40:40.097 DEBUG 6860 --- [nio-8080-exec-6] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Did not find handler method for [/hello]
2018-04-16 10:40:40.097 DEBUG 6860 --- [nio-8080-exec-6] a.e.w.s.ControllerEndpointHandlerMapping : Looking up handler method for path /hello
2018-04-16 10:40:40.098 DEBUG 6860 --- [nio-8080-exec-6] a.e.w.s.ControllerEndpointHandlerMapping : Did not find handler method for [/hello]
2018-04-16 10:40:40.098 DEBUG 6860 --- [nio-8080-exec-6] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /hello
2018-04-16 10:40:40.098 DEBUG 6860 --- [nio-8080-exec-6] s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method [public org.springframework.web.servlet.ModelAndView com.spring.controller.SpringController.hello()]
2018-04-16 10:40:40.098 DEBUG 6860 --- [nio-8080-exec-6] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'springController'
2018-04-16 10:40:40.099 DEBUG 6860 --- [nio-8080-exec-6] o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/web/hello]
2018-04-16 10:40:40.099 DEBUG 6860 --- [nio-8080-exec-6] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Looking up handler method for path /hello
2018-04-16 10:40:40.100 DEBUG 6860 --- [nio-8080-exec-6] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Did not find handler method for [/hello]
2018-04-16 10:40:40.100 DEBUG 6860 --- [nio-8080-exec-6] a.e.w.s.ControllerEndpointHandlerMapping : Looking up handler method for path /hello
2018-04-16 10:40:40.100 DEBUG 6860 --- [nio-8080-exec-6] a.e.w.s.ControllerEndpointHandlerMapping : Did not find handler method for [/hello]
2018-04-16 10:40:40.100 DEBUG 6860 --- [nio-8080-exec-6] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /hello
2018-04-16 10:40:40.101 DEBUG 6860 --- [nio-8080-exec-6] s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method [public org.springframework.web.servlet.ModelAndView com.spring.controller.SpringController.hello()]
2018-04-16 10:40:40.101 DEBUG 6860 --- [nio-8080-exec-6] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'springController'
2018-04-16 10:40:40.101 DEBUG 6860 --- [nio-8080-exec-6] o.s.web.servlet.DispatcherServlet        : Last-Modified value for [/web/hello] is: -1
2018-04-16 10:40:40.101 DEBUG 6860 --- [nio-8080-exec-6] o.j.s.OpenEntityManagerInViewInterceptor : Opening JPA EntityManager in OpenEntityManagerInViewInterceptor
2018-04-16 10:40:40.102 DEBUG 6860 --- [nio-8080-exec-6] o.s.w.servlet.view.BeanNameViewResolver  : No matching bean found for view name 'hello'
2018-04-16 10:40:40.103 DEBUG 6860 --- [nio-8080-exec-6] o.s.web.servlet.DispatcherServlet        : Rendering view [org.springframework.web.servlet.view.JstlView: name 'hello'; URL [/WEB-INF/pages/hello.jsp]] in DispatcherServlet with name 'dispatcherServlet'
2018-04-16 10:40:40.103 DEBUG 6860 --- [nio-8080-exec-6] o.s.web.servlet.view.JstlView            : Added model object 'name' of type [java.lang.String] to request in view with name 'hello'
2018-04-16 10:40:40.104 DEBUG 6860 --- [nio-8080-exec-6] o.s.web.servlet.view.JstlView            : Forwarding to resource [/WEB-INF/pages/hello.jsp] in InternalResourceView 'hello'
2018-04-16 10:40:40.105 DEBUG 6860 --- [nio-8080-exec-6] o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/web/WEB-INF/pages/hello.jsp]
2018-04-16 10:40:40.105 DEBUG 6860 --- [nio-8080-exec-6] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Looking up handler method for path /WEB-INF/pages/hello.jsp
2018-04-16 10:40:40.106 DEBUG 6860 --- [nio-8080-exec-6] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Did not find handler method for [/WEB-INF/pages/hello.jsp]
2018-04-16 10:40:40.106 DEBUG 6860 --- [nio-8080-exec-6] a.e.w.s.ControllerEndpointHandlerMapping : Looking up handler method for path /WEB-INF/pages/hello.jsp
2018-04-16 10:40:40.107 DEBUG 6860 --- [nio-8080-exec-6] a.e.w.s.ControllerEndpointHandlerMapping : Did not find handler method for [/WEB-INF/pages/hello.jsp]
2018-04-16 10:40:40.107 DEBUG 6860 --- [nio-8080-exec-6] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /WEB-INF/pages/hello.jsp
2018-04-16 10:40:40.108 DEBUG 6860 --- [nio-8080-exec-6] s.w.s.m.m.a.RequestMappingHandlerMapping : Did not find handler method for [/WEB-INF/pages/hello.jsp]
2018-04-16 10:40:40.108 DEBUG 6860 --- [nio-8080-exec-6] o.s.w.s.handler.SimpleUrlHandlerMapping  : Matching patterns for request [/WEB-INF/pages/hello.jsp] are [/**]
2018-04-16 10:40:40.109 DEBUG 6860 --- [nio-8080-exec-6] o.s.w.s.handler.SimpleUrlHandlerMapping  : URI Template variables for request [/WEB-INF/pages/hello.jsp] are {}
2018-04-16 10:40:40.109 DEBUG 6860 --- [nio-8080-exec-6] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapping [/WEB-INF/pages/hello.jsp] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler@2a8dbf73] and 1 interceptor
2018-04-16 10:40:40.109 DEBUG 6860 --- [nio-8080-exec-6] o.s.web.servlet.DispatcherServlet        : Last-Modified value for [/web/WEB-INF/pages/hello.jsp] is: -1
2018-04-16 10:40:40.109 DEBUG 6860 --- [nio-8080-exec-6] o.s.web.servlet.DispatcherServlet        : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
2018-04-16 10:40:40.109 DEBUG 6860 --- [nio-8080-exec-6] o.s.web.servlet.DispatcherServlet        : Successfully completed request
2018-04-16 10:40:40.110 DEBUG 6860 --- [nio-8080-exec-6] o.j.s.OpenEntityManagerInViewInterceptor : Closing JPA EntityManager in OpenEntityManagerInViewInterceptor
2018-04-16 10:40:40.110 DEBUG 6860 --- [nio-8080-exec-6] o.s.orm.jpa.EntityManagerFactoryUtils    : Closing JPA EntityManager
2018-04-16 10:40:40.110 DEBUG 6860 --- [nio-8080-exec-6] o.s.web.servlet.DispatcherServlet        : Successfully completed request
2018-04-16 10:40:40.113 DEBUG 6860 --- [nio-8080-exec-6] o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/web/error]
2018-04-16 10:40:40.113 DEBUG 6860 --- [nio-8080-exec-6] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Looking up handler method for path /error
2018-04-16 10:40:40.114 DEBUG 6860 --- [nio-8080-exec-6] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Did not find handler method for [/error]
2018-04-16 10:40:40.114 DEBUG 6860 --- [nio-8080-exec-6] a.e.w.s.ControllerEndpointHandlerMapping : Looking up handler method for path /error
2018-04-16 10:40:40.114 DEBUG 6860 --- [nio-8080-exec-6] a.e.w.s.ControllerEndpointHandlerMapping : Did not find handler method for [/error]
2018-04-16 10:40:40.114 DEBUG 6860 --- [nio-8080-exec-6] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /error
2018-04-16 10:40:40.115 DEBUG 6860 --- [nio-8080-exec-6] 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-04-16 10:40:40.115 DEBUG 6860 --- [nio-8080-exec-6] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'basicErrorController'
2018-04-16 10:40:40.115 DEBUG 6860 --- [nio-8080-exec-6] o.s.web.servlet.DispatcherServlet        : Last-Modified value for [/web/error] is: -1
2018-04-16 10:40:40.115 DEBUG 6860 --- [nio-8080-exec-6] o.j.s.OpenEntityManagerInViewInterceptor : Opening JPA EntityManager in OpenEntityManagerInViewInterceptor
2018-04-16 10:40:40.116 DEBUG 6860 --- [nio-8080-exec-6] o.s.c.e.PropertySourcesPropertyResolver  : Found key 'spring.template.provider.cache' in PropertySource 'configurationProperties' with value of type String
2018-04-16 10:40:40.118 DEBUG 6860 --- [nio-8080-exec-6] o.s.c.e.PropertySourcesPropertyResolver  : Found key 'spring.template.provider.cache' in PropertySource 'configurationProperties' with value of type String
2018-04-16 10:40:40.120 DEBUG 6860 --- [nio-8080-exec-6] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'error'
2018-04-16 10:40:40.120 DEBUG 6860 --- [nio-8080-exec-6] o.s.web.servlet.DispatcherServlet        : Rendering view [org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$SpelView@35300951] in DispatcherServlet with name 'dispatcherServlet'
2018-04-16 10:40:40.121 DEBUG 6860 --- [nio-8080-exec-6] o.j.s.OpenEntityManagerInViewInterceptor : Closing JPA EntityManager in OpenEntityManagerInViewInterceptor
2018-04-16 10:40:40.121 DEBUG 6860 --- [nio-8080-exec-6] o.s.orm.jpa.EntityManagerFactoryUtils    : Closing JPA EntityManager
2018-04-16 10:40:40.121 DEBUG 6860 --- [nio-8080-exec-6] o.s.web.servlet.DispatcherServlet        : Successfully completed request

我试着像这样实现WebApplicationInitializer,但似乎不起作用:

代码语言:javascript
复制
public class WebServletConfiguration implements WebApplicationInitializer{

    public void onStartup(ServletContext ctx) throws ServletException {
        AnnotationConfigWebApplicationContext webCtx = new AnnotationConfigWebApplicationContext();
        webCtx.register(SpringConfig.class);
        webCtx.setServletContext(ctx);
        //DispatcherServlet, acts as the FrontController of the Spring MVC application.
        ServletRegistration.Dynamic servlet = ctx.addServlet("dispatcher", new DispatcherServlet(webCtx)); 
        servlet.setLoadOnStartup(1);
        servlet.addMapping("/");
    }


    }

我将bean添加到我的Application.java中:

代码语言:javascript
复制
@Bean
    public ServletRegistrationBean hello() {
        DispatcherServlet dispatcherServlet = new DispatcherServlet();

        AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
        applicationContext.register(SpringConfig.class);
        dispatcherServlet.setApplicationContext(applicationContext);

        ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(dispatcherServlet, "/hello");
        servletRegistrationBean.setName("hello-world");
        return servletRegistrationBean;
    }

我的日志在下面发生了变化:

代码语言:javascript
复制
Looking up handler method for path /hello
2018-04-16 11:26:54.748 DEBUG 5684 --- [nio-8080-exec-3] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Did not find handler method for [/hello]
2018-04-16 11:26:54.748 DEBUG 5684 --- [nio-8080-exec-3] a.e.w.s.ControllerEndpointHandlerMapping : Looking up handler method for path /hello
2018-04-16 11:26:54.748 DEBUG 5684 --- [nio-8080-exec-3] a.e.w.s.ControllerEndpointHandlerMapping : Did not find handler method for [/hello]
2018-04-16 11:26:54.748 DEBUG 5684 --- [nio-8080-exec-3] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /hello
2018-04-16 11:26:54.748 DEBUG 5684 --- [nio-8080-exec-3] s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method [public org.springframework.web.servlet.ModelAndView com.spring.controller.SpringController.hello()]
2018-04-16 11:26:54.748 DEBUG 5684 --- [nio-8080-exec-3] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'springController'
2018-04-16 11:26:54.749 DEBUG 5684 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name 'hello-world' processing GET request for [/web/hello]
2018-04-16 11:26:54.749 DEBUG 5684 --- [nio-8080-exec-3] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Looking up handler method for path /hello
2018-04-16 11:26:54.749 DEBUG 5684 --- [nio-8080-exec-3] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Did not find handler method for [/hello]
2018-04-16 11:26:54.749 DEBUG 5684 --- [nio-8080-exec-3] a.e.w.s.ControllerEndpointHandlerMapping : Looking up handler method for path /hello
2018-04-16 11:26:54.749 DEBUG 5684 --- [nio-8080-exec-3] a.e.w.s.ControllerEndpointHandlerMapping : Did not find handler method for [/hello]
2018-04-16 11:26:54.749 DEBUG 5684 --- [nio-8080-exec-3] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /hello
2018-04-16 11:26:54.750 DEBUG 5684 --- [nio-8080-exec-3] s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method [public org.springframework.web.servlet.ModelAndView com.spring.controller.SpringController.hello()]
2018-04-16 11:26:54.750 DEBUG 5684 --- [nio-8080-exec-3] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'springController'
2018-04-16 11:26:54.750 DEBUG 5684 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet        : Last-Modified value for [/web/hello] is: -1
2018-04-16 11:26:54.750 DEBUG 5684 --- [nio-8080-exec-3] o.j.s.OpenEntityManagerInViewInterceptor : Opening JPA EntityManager in OpenEntityManagerInViewInterceptor
2018-04-16 11:26:54.751 DEBUG 5684 --- [nio-8080-exec-3] o.s.w.servlet.view.BeanNameViewResolver  : Found matching bean for view name 'hello' - to be ignored since it does not implement View
2018-04-16 11:26:54.751 DEBUG 5684 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet        : Rendering view [org.springframework.web.servlet.view.JstlView: name 'hello'; URL [/WEB-INF/pages/hello.jsp]] in DispatcherServlet with name 'hello-world'
2018-04-16 11:26:54.751 DEBUG 5684 --- [nio-8080-exec-3] o.s.web.servlet.view.JstlView            : Added model object 'name' of type [java.lang.String] to request in view with name 'hello'
2018-04-16 11:26:54.751 DEBUG 5684 --- [nio-8080-exec-3] o.s.web.servlet.view.JstlView            : Forwarding to resource [/WEB-INF/pages/hello.jsp] in InternalResourceView 'hello'
2018-04-16 11:26:54.752 DEBUG 5684 --- [nio-8080-exec-3] o.j.s.OpenEntityManagerInViewInterceptor : Closing JPA EntityManager in OpenEntityManagerInViewInterceptor
2018-04-16 11:26:54.752 DEBUG 5684 --- [nio-8080-exec-3] o.s.orm.jpa.EntityManagerFactoryUtils    : Closing JPA EntityManager
2018-04-16 11:26:54.752 DEBUG 5684 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet        : Successfully completed request

在我向Application.java添加了@EnableAutoConfiguration @EnableWebMvc @ComponentScan({"com.spring"})之后

代码语言:javascript
复制
Looking up handler method for path /hello
2018-04-16 12:34:20.346 DEBUG 6464 --- [nio-8080-exec-2] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Did not find handler method for [/hello]
2018-04-16 12:34:20.346 DEBUG 6464 --- [nio-8080-exec-2] a.e.w.s.ControllerEndpointHandlerMapping : Looking up handler method for path /hello
2018-04-16 12:34:20.346 DEBUG 6464 --- [nio-8080-exec-2] a.e.w.s.ControllerEndpointHandlerMapping : Did not find handler method for [/hello]
2018-04-16 12:34:20.346 DEBUG 6464 --- [nio-8080-exec-2] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /hello
2018-04-16 12:34:20.347 DEBUG 6464 --- [nio-8080-exec-2] s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method [public org.springframework.web.servlet.ModelAndView com.spring.controller.SpringController.hello()]
2018-04-16 12:34:20.347 DEBUG 6464 --- [nio-8080-exec-2] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'springController'
2018-04-16 12:34:20.347 DEBUG 6464 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/web/hello]
2018-04-16 12:34:20.347 DEBUG 6464 --- [nio-8080-exec-2] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Looking up handler method for path /hello
2018-04-16 12:34:20.348 DEBUG 6464 --- [nio-8080-exec-2] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Did not find handler method for [/hello]
2018-04-16 12:34:20.348 DEBUG 6464 --- [nio-8080-exec-2] a.e.w.s.ControllerEndpointHandlerMapping : Looking up handler method for path /hello
2018-04-16 12:34:20.348 DEBUG 6464 --- [nio-8080-exec-2] a.e.w.s.ControllerEndpointHandlerMapping : Did not find handler method for [/hello]
2018-04-16 12:34:20.348 DEBUG 6464 --- [nio-8080-exec-2] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /hello
2018-04-16 12:34:20.348 DEBUG 6464 --- [nio-8080-exec-2] s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method [public org.springframework.web.servlet.ModelAndView com.spring.controller.SpringController.hello()]
2018-04-16 12:34:20.348 DEBUG 6464 --- [nio-8080-exec-2] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'springController'
2018-04-16 12:34:20.349 DEBUG 6464 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet        : Last-Modified value for [/web/hello] is: -1
2018-04-16 12:34:20.349 DEBUG 6464 --- [nio-8080-exec-2] o.j.s.OpenEntityManagerInViewInterceptor : Opening JPA EntityManager in OpenEntityManagerInViewInterceptor
2018-04-16 12:34:20.349 DEBUG 6464 --- [nio-8080-exec-2] o.s.w.servlet.view.BeanNameViewResolver  : No matching bean found for view name 'hello'
2018-04-16 12:34:20.350 DEBUG 6464 --- [nio-8080-exec-2] o.s.b.f.s.DefaultListableBeanFactory     : Invoking afterPropertiesSet() on bean with name 'hello'
2018-04-16 12:34:20.350 DEBUG 6464 --- [nio-8080-exec-2] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
2018-04-16 12:34:20.350 DEBUG 6464 --- [nio-8080-exec-2] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
2018-04-16 12:34:20.350 DEBUG 6464 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet        : Rendering view [org.springframework.web.servlet.view.JstlView: name 'hello'; URL [/WEB-INF/pages/hello.jsp]] in DispatcherServlet with name 'dispatcherServlet'
2018-04-16 12:34:20.350 DEBUG 6464 --- [nio-8080-exec-2] o.s.web.servlet.view.JstlView            : Added model object 'name' of type [java.lang.String] to request in view with name 'hello'
2018-04-16 12:34:20.350 DEBUG 6464 --- [nio-8080-exec-2] o.s.web.servlet.view.JstlView            : Forwarding to resource [/WEB-INF/pages/hello.jsp] in InternalResourceView 'hello'
2018-04-16 12:34:20.351 DEBUG 6464 --- [nio-8080-exec-2] o.j.s.OpenEntityManagerInViewInterceptor : Closing JPA EntityManager in OpenEntityManagerInViewInterceptor
2018-04-16 12:34:20.351 DEBUG 6464 --- [nio-8080-exec-2] o.s.orm.jpa.EntityManagerFactoryUtils    : Closing JPA EntityManager
2018-04-16 12:34:20.351 DEBUG 6464 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet        : Successfully completed request
2018-04-16 12:34:20.355 DEBUG 6464 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/web/error]
2018-04-16 12:34:20.355 DEBUG 6464 --- [nio-8080-exec-2] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Looking up handler method for path /error
2018-04-16 12:34:20.357 DEBUG 6464 --- [nio-8080-exec-2] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Did not find handler method for [/error]
2018-04-16 12:34:20.357 DEBUG 6464 --- [nio-8080-exec-2] a.e.w.s.ControllerEndpointHandlerMapping : Looking up handler method for path /error
2018-04-16 12:34:20.357 DEBUG 6464 --- [nio-8080-exec-2] a.e.w.s.ControllerEndpointHandlerMapping : Did not find handler method for [/error]
2018-04-16 12:34:20.357 DEBUG 6464 --- [nio-8080-exec-2] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /error
2018-04-16 12:34:20.361 DEBUG 6464 --- [nio-8080-exec-2] 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-04-16 12:34:20.361 DEBUG 6464 --- [nio-8080-exec-2] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'basicErrorController'
2018-04-16 12:34:20.361 DEBUG 6464 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet        : Last-Modified value for [/web/error] is: -1
2018-04-16 12:34:20.361 DEBUG 6464 --- [nio-8080-exec-2] o.j.s.OpenEntityManagerInViewInterceptor : Opening JPA EntityManager in OpenEntityManagerInViewInterceptor
2018-04-16 12:34:20.362 DEBUG 6464 --- [nio-8080-exec-2] o.s.c.e.PropertySourcesPropertyResolver  : Found key 'spring.template.provider.cache' in PropertySource 'configurationProperties' with value of type String
2018-04-16 12:34:20.364 DEBUG 6464 --- [nio-8080-exec-2] o.s.c.e.PropertySourcesPropertyResolver  : Could not find key 'spring.mvc.view.prefix' in any property source
2018-04-16 12:34:20.364 DEBUG 6464 --- [nio-8080-exec-2] o.s.c.e.PropertySourcesPropertyResolver  : Could not find key 'spring.mvc.view.suffix' in any property source
2018-04-16 12:34:20.365 DEBUG 6464 --- [nio-8080-exec-2] o.s.c.e.PropertySourcesPropertyResolver  : Found key 'spring.template.provider.cache' in PropertySource 'configurationProperties' with value of type String
2018-04-16 12:34:20.366 DEBUG 6464 --- [nio-8080-exec-2] o.s.c.e.PropertySourcesPropertyResolver  : Could not find key 'spring.mvc.view.prefix' in any property source
2018-04-16 12:34:20.366 DEBUG 6464 --- [nio-8080-exec-2] o.s.c.e.PropertySourcesPropertyResolver  : Could not find key 'spring.mvc.view.suffix' in any property source
2018-04-16 12:34:20.367 DEBUG 6464 --- [nio-8080-exec-2] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'error'
2018-04-16 12:34:20.367 DEBUG 6464 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet        : Rendering view [org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$SpelView@104b554c] in DispatcherServlet with name 'dispatcherServlet'
2018-04-16 12:34:20.368 DEBUG 6464 --- [nio-8080-exec-2] o.j.s.OpenEntityManagerInViewInterceptor : Closing JPA EntityManager in OpenEntityManagerInViewInterceptor
2018-04-16 12:34:20.368 DEBUG 6464 --- [nio-8080-exec-2] o.s.orm.jpa.EntityManagerFactoryUtils    : Closing JPA EntityManager
2018-04-16 12:34:20.368 DEBUG 6464 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet        : Successfully completed request
2018-04-16 12:34:41.078 DEBUG 6464 --- [l-1 housekeeper] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Pool stats (total=10, active=0, idle=10, waiting=0)

但没什么..。我正在阅读所有文档,但不明白我遗漏了什么。

EN

回答 1

Stack Overflow用户

发布于 2018-04-22 00:33:00

我在你的控制器中看不到任何http://localhost:8080/web/hello的映射。

试试这个:http://localhost:8080/hello

这是我当前的配置,它工作正常

代码语言:javascript
复制
@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter{

    //Static views
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/home").setViewName("home");
        registry.addViewController("/").setViewName("login");
        registry.addViewController("/403").setViewName("403");
    }    


    @Bean
    public InternalResourceViewResolver viewResolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/WEB-INF/views/");
        resolver.setSuffix(".jsp");
        return resolver;
    }    

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49853084

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档