idea下 spring boot项目使用 jsp

webapp文件夹 放入 src/main 下:

4cc7a856ea3c549aae680ab1f90edb67805.jpg

方法1:

在pom 文件添加:

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>src/main/webapp</directory>
                <!--注意此次必须要放在此目录下才能被访问到 -->
                <targetPath>META-INF/resources</targetPath>
                <includes>
                    <include>**/**</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/*</include>
                </includes>
            </resource>
        </resources>
    </build>

 

方法2:

增加一个配置类:

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.File;

@Configuration
public class TomcatConfig {
    @Value("${tomcat.factory.doc.root}")
    private String rootDoc;
    @Bean
    public AbstractServletWebServerFactory embeddedServletContainerFactory() {
       
        TomcatServletWebServerFactory tomcatServletWebServerFactory = new TomcatServletWebServerFactory();
        tomcatServletWebServerFactory.setDocumentRoot(
                new File(rootDoc));
        return  tomcatServletWebServerFactory;
    }
}

在配置文件中,配置当前webapp文件夹所在位置:

tomcat.factory.doc.root=D:/project/myBlog/blog-web/src/main/webapp

 

方法3:

1.打开项目结构:

2.修改为如下结构,即可:

4560d37f0b79726d704deddfd42e979dc9d.jpg

该方法仅针对当前项目为独立的项目,不属于其他项目的module。若当前项目为其他项目的module,则只能使用前两种方法。

 

转载于:https://my.oschina.net/langwanghuangshifu/blog/3000516

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值