Spring boot Could not resolve view with name

匿名 (未验证) 提交于 2019-12-03 08:59:04

问题:

Here's my spring boot configuration

@EnableAutoConfiguration @EnableWebMvc @ComponentScan({"org.app.genesis.client.controller","org.app.genesis.commons.service",     "org.app.app.commons.security","org.app.genesis.inventory.service","org.app.genesis.client.auth"}) @EnableJpaRepositories(basePackages = "org.app.genesis.*.repo") @EntityScan(basePackages = "org.app.genesis.*.model") public class Application extends WebMvcConfigurerAdapter   {      @Value("${driver.className}")     private String DRIVER_CLASSNAME;      @Value("${db.url}")     private String DB_URL;      @Value("${db.username}")     private String DB_USERNAME;      @Value("${db.password}")     private String DB_PASSWORD;      @Value("${hibernate.hbm2ddl.auto}")     private String HBM_DDLAUTO;      @Value("${hibernate.packagesToScan}")     private String PACKAGES_TO_SCAN;      @Value("${hibernate.sql.dialect}")     private String SQL_DIALECT;      @Value("${hibernate.connection.pool_size}")     private int CONNECTION_POOL_SIZE;      @Value("${hibernate.format.sql}")     private boolean FORMAT_SQL;      @Value("${hibernate.multiTenancy}")     private String HIBERNATE_MULTITENANCY;      @Value("${hibernate.tenant_identifier_resolver}")     private String TENANT_IDENTIFIER_RESOLVER;      @Value("${hibernate.multi_tenant_connection_provider}")     private String TENANT_IDENTIFIER_CONNECTION_PROVIDER;       /**      * Execution Point of our application      *      * @param args      * @throws Exception      */     public static void main(String[] args) throws Exception {         new SpringApplicationBuilder(Application.class).run(args);     }       /**      * HTTP Session Object scoped proxy for CheckOutCounter      * that is used For storing items      * temporarily for each user Session      */     @Bean     @Scope(value = "session",proxyMode = ScopedProxyMode.TARGET_CLASS)     public CheckOutCounter checkOutCounter(){         return new CheckOutCounter();     }      /**      * Creates a bean of a HttpRequestMappingHandler Adapter      * @return HttpRequestMappingHandler      */     @Bean     public RequestMappingHandlerAdapter requestMappingHandlerAdapter(){         RequestMappingHandlerAdapter requestMappingHandlerAdapter = new RequestMappingHandlerAdapter();         List<HttpMessageConverter<?>> messageConverterList = new ArrayList<>();         messageConverterList.add(new org.springframework.http.converter.json.MappingJackson2HttpMessageConverter());         requestMappingHandlerAdapter.setMessageConverters(messageConverterList);         return  requestMappingHandlerAdapter;     }       /**      * Rest Template Configurations.      */     @Bean     public RestTemplate restTemplate(){         return new RestTemplate(httpComponentsClientHttpRequestFactory());     }      @Bean     public HttpComponentsClientHttpRequestFactory httpComponentsClientHttpRequestFactory(){         HttpComponentsClientHttpRequestFactory httpComponentsClientHttpRequestFactory =             new HttpComponentsClientHttpRequestFactory();          httpComponentsClientHttpRequestFactory.setConnectionRequestTimeout(60000);         httpComponentsClientHttpRequestFactory.setReadTimeout(60000);         return httpComponentsClientHttpRequestFactory;     }      /**      * Data Source and Entity manager Configurations      *      */     @Bean     public DataSource dataSource() {         com.zaxxer.hikari.HikariDataSource dataSource = new com.zaxxer.hikari.HikariDataSource();         dataSource.setDriverClassName(DRIVER_CLASSNAME);         dataSource.setUsername(DB_USERNAME);         dataSource.setPassword(DB_PASSWORD);         dataSource.setJdbcUrl(DB_URL);         dataSource.setMaximumPoolSize(CONNECTION_POOL_SIZE);         return dataSource;     }      @Bean(name = "entityManagerFactory")     public LocalContainerEntityManagerFactoryBean entityManagerFactory(){         LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();          Properties jpaProperties = new Properties();         jpaProperties.put("hibernate.format_sql", FORMAT_SQL);         jpaProperties.put("hibernate.multiTenancy", HIBERNATE_MULTITENANCY);         jpaProperties.put("hibernate.tenant_identifier_resolver", TENANT_IDENTIFIER_RESOLVER);         jpaProperties.put("hibernate.multi_tenant_connection_provider", TENANT_IDENTIFIER_CONNECTION_PROVIDER);          HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();         jpaVendorAdapter.setDatabasePlatform(SQL_DIALECT);         jpaVendorAdapter.setShowSql(true);          entityManagerFactoryBean.setDataSource(dataSource());         entityManagerFactoryBean.setPackagesToScan(PACKAGES_TO_SCAN);          entityManagerFactoryBean.setJpaProperties(jpaProperties);         entityManagerFactoryBean.setJpaVendorAdapter(jpaVendorAdapter);         return entityManagerFactoryBean;     }      /**      *  Spring Security Configuration      *      */     @Configuration     @EnableWebSecurity     protected static class SecurityConfig extends WebSecurityConfigurerAdapter {          @Autowired         @Qualifier("customAuthenticationProvider")         private AuthenticationProvider customAuthProvider;          @Override         protected void configure(AuthenticationManagerBuilder auth) {             auth.authenticationProvider(customAuthProvider);         }           @Override         protected void configure(HttpSecurity http) throws Exception {             http                 .authorizeRequests()                 .antMatchers("/**"                 )                 .hasAnyRole("ADMIN","CLERK")                 .and()                 .formLogin()                 .loginPage("/login")                 .loginProcessingUrl("/j_spring_security_check")                 .defaultSuccessUrl("/product/search", true)                 .permitAll()                 .and()                 .csrf()                 .disable()                 .logout()                 .logoutUrl("/j_spring_security_logout")                 .logoutSuccessUrl("/login");         }     } } 

here's a gist of my spring boot application.properties

#SPRING MVC spring.view.prefix: /WEB-INF/jsp/ spring.view.suffix: .jsp security.basic.enabled=false logging.level.org.springframework.security=DEBUG 

The Controller that's being read

@Controller public class ClientDashboardController  {      private Logger logger = LoggerFactory.getLogger(ClientDashboardController.class);      @RequestMapping(value="/dashboard")     public String displayDashboard() {          Object principal =                 SecurityContextHolder.getContext().getAuthentication().getPrincipal();          return "dashboard";     }       @RequestMapping(value="/login")     public String index() {         return "index";     } } 

Gist of my pom.xml

<dependencies>     <dependency>         <groupId>org.springframework.boot</groupId>         <artifactId>spring-boot-actuator</artifactId>     </dependency>     <dependency>         <groupId>org.springframework.boot</groupId>         <artifactId>spring-boot-starter-web</artifactId>     </dependency>     <dependency>         <groupId>org.springframework.boot</groupId>         <artifactId>spring-boot-starter-data-jpa</artifactId>     </dependency>     <dependency>         <groupId>org.apache.tomcat.embed</groupId>         <artifactId>tomcat-embed-jasper</artifactId>         <scope>provided</scope>     </dependency> 

And this is the error message

what did I configured wrong?

javax.servlet.ServletException: Could not resolve view with name 'index' in servlet with name 'dispatcherServlet'         at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1227) ~[spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]         at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1027) ~[spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]         at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:971) ~[spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]         at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) ~[spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]         at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966) [spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]         at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857) [spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]         at javax.servlet.http.HttpServlet.service(HttpServlet.java:618) [tomcat-embed-core-8.0.20.jar:8.0.20]         at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842) [spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]         at javax.servlet.http.HttpServlet.service(HttpServlet.java:725) [tomcat-embed-core-8.0.20.jar:8.0.20]         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) [tomcat-embed-core-8.0.20.jar:8.0.20]         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [tomcat-embed-core-8.0.20.jar:8.0.20]         at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat-embed-websocket-8.0.20.jar:8.0.20]         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [tomcat-embed-core-8.0.20.jar:8.0.20]         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [tomcat-embed-core-8.0.20.jar:8.0.20]         at org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration$ApplicationContextHeaderFilter.doFilterInternal(EndpointWebMvcAutoConfiguration.java:291) [spring-boot-actuator-1.2.3.RELEASE.jar:1.2.3.RELEASE]         at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [tomcat-embed-core-8.0.20.jar:8.0.20]         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [tomcat-embed-core-8.0.20.jar:8.0.20]         at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) [spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]         at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118) [spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]         at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84) [spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]         at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]         at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113) [spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]         at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]         at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103) [spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]         at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]         at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113) [spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]         at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]         at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154) [spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]         at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]         at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45) [spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]         at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]         at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199) [spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]         at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]         at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110) [spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]         at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]         at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:57) [spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]         at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]         at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]         at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87) [spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]         at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]         at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50) [spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]         at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]         at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]         at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192) [spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]         at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160) [spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [tomcat-embed-core-8.0.20.jar:8.0.20]         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [tomcat-embed-core-8.0.20.jar:8.0.20]         at org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebRequestTraceFilter.java:102) [spring-boot-actuator-1.2.3.RELEASE.jar:1.2.3.RELEASE]         at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [tomcat-embed-core-8.0.20.jar:8.0.20]         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [tomcat-embed-core-8.0.20.jar:8.0.20]         at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85) [spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]         at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [tomcat-embed-core-8.0.20.jar:8.0.20]         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [tomcat-embed-core-8.0.20.jar:8.0.20]         at org.springframework.boot.actuate.autoconfigure.MetricFilterAutoConfiguration$MetricsFilter.doFilterInternal(MetricFilterAutoConfiguration.java:90) [spring-boot-actuator-1.2.3.RELEASE.jar:1.2.3.RELEASE]         at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [tomcat-embed-core-8.0.20.jar:8.0.20]         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [tomcat-embed-core-8.0.20.jar:8.0.20]         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) [tomcat-embed-core-8.0.20.jar:8.0.20]         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) [tomcat-embed-core-8.0.20.jar:8.0.20]         at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) [tomcat-embed-core-8.0.20.jar:8.0.20]         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) [tomcat-embed-core-8.0.20.jar:8.0.20]         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [tomcat-embed-core-8.0.20.jar:8.0.20]         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [tomcat-embed-core-8.0.20.jar:8.0.20]         at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516) [tomcat-embed-core-8.0.20.jar:8.0.20]         at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1086) [tomcat-embed-core-8.0.20.jar:8.0.20]         at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:659) [tomcat-embed-core-8.0.20.jar:8.0.20]         at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223) [tomcat-embed-core-8.0.20.jar:8.0.20]         at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1558) [tomcat-embed-core-8.0.20.jar:8.0.20]         at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1515) [tomcat-embed-core-8.0.20.jar:8.0.20]         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_67]         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_67]         at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.0.20.jar:8.0.20]         at java.lang.Thread.run(Thread.java:745) [na:1.7.0_67] 11:09:35.095 [http-nio-8080-exec-2] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'delegatingApplicationListener' 11:09:35.096 [http-nio-8080-exec-2] DEBUG o.s.s.w.c.HttpSessionSecurityContextRepository - SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession. 11:09:35.096 [http-nio-8080-exec-2] DEBUG o.s.s.w.c.SecurityContextPersistenceFilter - SecurityContextHolder now cleared, as request processing completed 

回答1:

I've encountered this error already. I believe you are extending the wrong class. check this link

You need to extend your class to this SpringBootServletInitializer

@EnableAutoConfiguration @EnableWebMvc @ComponentScan({"org.app.genesis.client.controller","org.app.genesis.commons.service",     "org.app.app.commons.security","org.app.genesis.inventory.service","org.app.genesis.client.auth"}) @EnableJpaRepositories(basePackages = "org.app.genesis.*.repo") @EntityScan(basePackages = "org.app.genesis.*.model") public class Application extends SpringBootServletInitializer{   ... } 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!