在多模块化项目中查看解析器配置

Posted

技术标签:

【中文标题】在多模块化项目中查看解析器配置【英文标题】:View Resolver configuration in case multi modular project 【发布时间】:2018-10-02 21:41:35 【问题描述】:

我有一个由不同模块组成的 Spring Boot 项目。

Octava
|-Application
|-Business
|-Core

Application模块中,有核心的SpringBoot应用配置 Business 模块有网络配置。所以,在这个结构中,它遇到了一个错误

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?

【问题讨论】:

【参考方案1】:

我终于在这里找到了解决方案see topic 7.2。

所以,我只需要:

添加百里香依赖,

分级

compile group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf', version: '2.1.1.RELEASE'
将所有视图 webbapp 文件夹移动到资源/模板文件夹,

如果要更改视图解析器的后缀和前缀,可以在资源文件夹的 application.properties 中重新配置:

spring.thymeleaf.prefix=classpath:/templates/WEB-INF/views/
spring.thymeleaf.suffix=.jsp

可以在here找到完整的默认spring boot属性

【讨论】:

以上是关于在多模块化项目中查看解析器配置的主要内容,如果未能解决你的问题,请参考以下文章

在多模块 SDK Android 库项目中配置 proguard

如何在多模块 Gradle 项目中构建分发包?

ARouter 在多 module 项目中实战

ARouter 在多 module 项目中实战

ARouter 在多 module 项目中实战

maven ::在多模块项目中仅运行单个测试