Spring启动调度程序

时间:2018-04-16 08:45:29

标签: java spring spring-boot

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

@SpringBootApplication
public class Application {

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

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

@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;
    } 

}

我的控制器:

@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时,我有这个日志:

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,但似乎无法正常工作:

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("/");
    }


    }

我在我的Application.java中添加了bean:

@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;
    }

我的日志改变了:

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

我将@EnableAutoConfiguration @EnableWebMvc @ComponentScan({"com.spring"})添加到Application.java

之后
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)

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

1 个答案:

答案 0 :(得分:0)

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

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

这是我当前正常运行的配置

@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;
    }    

}