(六)Spring Boot整合-SpringMVC端口和静态资源

2021/8/19 6:06:22

本文主要是介绍(六)Spring Boot整合-SpringMVC端口和静态资源,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

目标:可以修改tomcat的端口和访问项目中的静态资源

分析:

●修改tomcat端口:查询**Properties,设置配置项(前缀+类变量名)到application.yml配置文件中

1)找到spring-boot-autoconfigure-xxx.jar

2)进入org.springframework. boot. autoconfigure->web-ServerProperties

3)Application.yml文件添加:

#tomcat端口修改
server:
  port: 80

访问:http://localhost/hello

结果:hello,spring boot!

●访问项目中的静态资源

静态资源放置的位置;放置静态资源并访问这些资源

public static class Resources {
    private static final String[] CLASSPATH_RESOURCE_LOCATIONS = new String[]{"classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/"};
    private String[] staticLocations;
    }

步骤:

resources下新建一个static包,将图片放在static包里(html 和 css都可以访问)

访问:http://localhost/3.jpeg

访问结果:



这篇关于(六)Spring Boot整合-SpringMVC端口和静态资源的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程