(六)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端口和静态资源的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-15鸿蒙生态设备数量超8亿台
- 2024-05-13TiDB + ES:转转业财系统亿级数据存储优化实践
- 2024-05-09“2024鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”实战课程已上线
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了
- 2024-05-09Google Chrome驱动程序 124.0.6367.62(正式版本)去哪下载?
- 2024-05-09有没有大佬知道这种数据应该怎么抓取呀?
- 2024-05-09这种运行结果里的10.100000001,怎么能最快改成10.1?