六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

访问结果:

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐