package com.ghgcn.springboot_view.config;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.io.File;
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
/**
* 解决idea JSP路径错误问题
* @return
*/
@Bean
public WebServerFactoryCustomizer<TomcatServletWebServerFactory> customizer() {
return (factory) -> {
factory.addContextCustomizers((context) -> {
//子模块 springboot-view
String relativePath = "springboot-view/src/main/webapp";
// 相对于 user.dir = D:\workspace\dive-in-spring-boot
File docBaseFile = new File(relativePath);
if(docBaseFile.exists()) { // 路径是否存在
// 解决 Maven 多模块 JSP 无法读取的问题
context.setDocBase(docBaseFile.getAbsolutePath());
}
}
);
};
}
}
解决idea JSP路径错误问题
最新推荐文章于 2024-02-04 15:22:57 发布