我有一个由不同模块组成的Spring Boot项目。
Octava
|-Application
|-Business
|-Core
在 Application 模块中,它具有核心SpringBoot应用程序配置 业务模块具有网络配置。因此,在这种结构中,它会遇到错误
2018-10-03 00:03:53 DEBUG JstlView:168 - Forwarding to resource [/WEB-INF/views/index.jsp] in InternalResourceView 'index'
2018-10-03 00:03:53 DEBUG DispatcherServlet:891 - DispatcherServlet with name 'dispatcherServlet' processing GET request for [/WEB-INF/views/index.jsp]
2018-10-03 00:03:53 DEBUG RequestMappingHandlerMapping:312 - Looking up handler method for path /WEB-INF/views/index.jsp
2018-10-03 00:03:53 DEBUG RequestMappingHandlerMapping:322 - Did not find handler method for [/WEB-INF/views/index.jsp]
2018-10-03 00:03:53 WARN PageNotFound:1205 - No mapping found for HTTP request with URI [/WEB-INF/views/index.jsp] in DispatcherServlet with name 'dispatcherServlet'
2018-10-03 00:03:53 DEBUG HstsHeaderWriter:129 - Not injecting HSTS header since it did not match the requestMatcher org.springframework.security.web.header.writers.HstsHeaderWriter$SecureRequestMatcher@73a34264
2018-10-03 00:03:53 DEBUG DispatcherServlet:1000 - Successfully completed request
当前ViewResolver配置
@Configuration
@EnableAspectJAutoProxy(proxyTargetClass = true)
@ComponentScan(basePackages = {"controller", "service", "dao", "model", "exception"})
@EnableWebMvc
public class BusinessMvcConfig extends WebMvcConfigurationSupport {
@Bean
public ViewResolver getViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setViewClass(JstlView.class);
resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".jsp");
return resolver;
}
@Bean(name = "multipartResolver")
public CommonsMultipartResolver multipartResolver() {
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
multipartResolver.setMaxUploadSize(500000000L);
return multipartResolver;
}
}
还可以在业务模块中设置运行良好的Spring Security。验证后,我收到404错误。
那么,问题是如何为这种结构设置View Resolver?
答案 0 :(得分:0)
我终于在see topic 7.2找到了解决方案。
所以,我所需要的:
Gradle
compile group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf', version: '2.1.1.RELEASE'
如果要更改视图解析器的后缀和前缀,可以在资源文件夹中的application.properties中重新配置它:
spring.thymeleaf.prefix=classpath:/templates/WEB-INF/views/
spring.thymeleaf.suffix=.jsp
可以找到here的全部默认Spring Boot属性