方便我们将资源配置以及模版&&静态文件分离出来,而不是打包在一起,比如以下的一个demo

参考配置:

server.port=8006
spring.application.name=appdemo
spring.resources.static-locations=pdf
spring.resources.chain.cache=false

maven 配置

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>com.dalong</groupId>
<artifactId>productapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <name>productapp</name>
<description>Demo project for Spring Boot</description> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-mockmvc</artifactId>
<scope>test</scope>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<!--核心进行需要处理的资源文件copy 而不是直接打包到jar 包中,方便我们进行修改 -->
<resources>
<resource>
<directory>src/main/resources/pdf/</directory>
<filtering>false</filtering>
<targetPath>${basedir}/target/pdf</targetPath>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>application.properties</include>
</includes>
</resource>
</resources>
</build> </project>

代码使用

```code
package com.dalong.productapp.com.dalong.productapp.controllers;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Map;
@RestController
public class ProductService {
@RequestMapping(value = "/productionStream")
public Object productsList() throws IOException {

     Map<String,String> products=new HashMap<>();
products.put("name","appdemo");
products.put("amount","10");
File file = new File("pdf/myinfo.txt");
products.put("myfile",file.getCanonicalPath());
return products;
}

}

```

项目结构

构建生成结果

classes 目录

参考资料

https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html

 
 
 
 

spring boot 使用spring.resources.static-locations 分离系统模版&&资源文件的更多相关文章

  1. Spring Boot 2.x以后static下面的静态资源被拦截

    今天创建一个新的Spring Boot项目,没注意到spring boot的版本,发现静态资源无法访问.百度一下发现好像是Spring Boot 2.0版本以后static目录不能直接访问. 接下来直 ...

  2. (转)spring boot实战(第六篇)加载application资源文件源码分析

    原文:http://blog.csdn.net/liaokailin/article/details/48878447

  3. Spring Boot 获取 java resources 下文件

    Spring Boot 获取 java resources 下文件 Spring Boot 获取 resources 目录下的目录(例:获取 resources 目录下的 template 目录): ...

  4. spring boot+freemarker+spring security标签权限判断

    spring boot+freemarker+spring security标签权限判断 SpringBoot+SpringSecurity+Freemarker项目中在页面上使用security标签 ...

  5. Spring Boot干货系列:(六)静态资源和拦截器处理

    Spring Boot干货系列:(六)静态资源和拦截器处理 原创 2017-04-05 嘟嘟MD 嘟爷java超神学堂 前言 本章我们来介绍下SpringBoot对静态资源的支持以及很重要的一个类We ...

  6. Spring Boot -- 认识Spring Boot

    在前面我们已经学习过Srping MVC框架,我们需要配置web.xml.spring mvc配置文件,tomcat,是不是感觉配置较为繁琐.那我们今天不妨来试试使用Spring Boot,Sprin ...

  7. Spring Boot (一): Spring Boot starter自定义

    前些日子在公司接触了spring boot和spring cloud,有感于其大大简化了spring的配置过程,十分方便使用者快速构建项目,而且拥有丰富的starter供开发者使用.但是由于其自动化配 ...

  8. Spring Boot与Spring MVC集成启动过程源码分析

    开源项目推荐 Pepper Metrics是我与同事开发的一个开源工具(https://github.com/zrbcool/pepper-metrics),其通过收集jedis/mybatis/ht ...

  9. SpringBoot系列:Spring Boot集成Spring Cache,使用EhCache

    前面的章节,讲解了Spring Boot集成Spring Cache,Spring Cache已经完成了多种Cache的实现,包括EhCache.RedisCache.ConcurrentMapCac ...

随机推荐

  1. Java新建线程的3种方法

    Java新建线程的3种方法 =================== Java创建线程有3种方法:(1)继承Thread;(2)实现Runnable接口:(3)实现Callable接口; 由于Java只 ...

  2. MVVM模式的3种command总结[1]--DelegateCommand

    MVVM模式的3种command总结[1]--DelegateCommand 查了不少资料,大概理清楚的就是有3种.当然类名可以自己取了,不过为了便于记忆和区分,还是和看到的文章里面用一样的类名. 1 ...

  3. 12 Essential Bootstrap Tools for Web Designers

    12 Essential Bootstrap Tools for Web Designers Posted by vikas on June 6, 2014, filed in: Tools, Web ...

  4. Mysql存储过程、索引

    sql语句执行顺序: from--->where--->group by--->having--->计算所有的表达式--->order by--->select 输 ...

  5. HDU 5687 字典树入门

    Problem C Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

  6. JAVA经典总结

    Java经典实例(第二版) 1. 获取环境变量 Java代码 1. System.getenv("PATH"); 2. System.getenv("JAVA_HOME& ...

  7. linux杀毒软件clamav安装与使用

    #clamav安装与使用 ###第一步:Clamav下载http://www.clamav.net/downloads wget http://www.clamav.net/downloads/pro ...

  8. python:打包成exe程序

    1.需要安装 py2exe 2.示例代码: #exetest.py #创建一个gui界面,只用一个标签和按钮,无功能 from Tkinter import * win = Tk() label = ...

  9. 关于px em rem的一点小总结

    2015-11-28 06:06:40 概念 都是CSS单位. px:像素 Pixel.像素 (计算机屏幕上的一个点) em:1em 等于当前的字体尺寸. 2em 等于当前字体尺寸的两倍. 例如,如果 ...

  10. 12.18 微信扫码获取openid与登陆

    官方文档: https://open.weixin.qq.com/ 1.先获取code 1-1 配置项目配置文件 wechat: mpAppId: wxd898fcb01713c658 mpAppSe ...