module1(如:封装好的一套组织机构、权限、角色、用户管理模块)包含jsp页面,module2(具体业务应用场景开发)依赖module1,结构图以下:java
parent │ └── module1 │ │── ... │ └── src/main/resources │ │── mapper │ │── public │ │ ... │ src/main/webapp │ └── WEB-INF │ └── jsp │ └── module2 │ ...
module1's pom.xml的build标签内中添加resources:web
<resources> <!-- 打包时将jsp文件拷贝到META-INF目录下--> <resource> <!-- 指定resources插件处理哪一个目录下的资源文件 --> <directory>src/main/webapp</directory> <!-- 注意必需要放在此目录下才能被访问到--> <targetPath>META-INF/resources</targetPath> <includes> <include>**/**</include> </includes> </resource> <resource> <directory>src/main/resources/public</directory> <targetPath>META-INF/resources</targetPath> <includes> <include>**/**</include> </includes> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**/**</include> </includes> <filtering>false</filtering> </resource> </resources>
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.springframework.web.servlet.view.InternalResourceViewResolver; @Configuration public class WebConfig extends WebMvcConfigurerAdapter { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/**").addResourceLocations("/"); } /** * 多模块的jsp访问,默认是src/main/webapp,可是多模块的目录只设置yml文件不行 * @return */ @Bean public InternalResourceViewResolver viewResolver() { InternalResourceViewResolver resolver = new InternalResourceViewResolver(); resolver.setViewClass(org.springframework.web.servlet.view.JstlView.class); // jsp目录 resolver.setPrefix("/WEB-INF/jsp/"); // 后缀 resolver.setSuffix(".jsp"); return resolver; } }