(六)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

访问结果:

posted @ 2021-08-19 01:57  只要不兔的学习笔记  阅读(146)  评论(0)    收藏  举报