读取资源文件

@RestController
@EnableAutoConfiguration
public class ResourcesController {
@Autowired
private ResourceLoader resourceLoader; @RequestMapping(value = "/get-resources", method = RequestMethod.GET)
public String getResources() throws IOException {
String content = IOUtils.toString(resourceLoader.getResource("classpath:test.txt").getInputStream(), "UTF-8");
return "the content of resources:" + content;
} public static void main(String[] args) {
SpringApplication.run(ResourcesController.class, args);
}
}

参考链接: Spring Boot get resource file example

获取 properties 配置项

  1. 通过 @Value("${config.key.name}");
  2. 通过 Environment bean;
@Controller
@Configuration
@PropertySource("classpath:system.properties")
public class SimpleController {
@Value("${server.address}")
private String serverAddress; @Autowired
private Environment env; @RequestMapping("/test-configuration-annotation")
@ResponseBody
public String testProperties() {
return "serverAddress: " + env.getProperty("server.address") +
" serverPort: " + env.getProperty("server.port");
}
}

参考链接: Read values from properties file in Spring

SpringBoot Tips的更多相关文章

  1. springboot kafka集成(实现producer和consumer)

    本文介绍如何在springboot项目中集成kafka收发message. 1.先解决依赖 springboot相关的依赖我们就不提了,和kafka相关的只依赖一个spring-kafka集成包 &l ...

  2. springboot mybatis优雅的添加多数据源

    springboot的原则是简化配置,本文试图不通过xml配置,使用configuration配置数据源,并进行简单的数据访问. 并且配置了多数据源,在开发过程中这种场景很容易遇到. 1.依赖 spr ...

  3. SpringBoot实战 之 异常处理篇

    在互联网时代,我们所开发的应用大多是直面用户的,程序中的任何一点小疏忽都可能导致用户的流失,而程序出现异常往往又是不可避免的,那该如何减少程序异常对用户体验的影响呢?其实方法很简单,对异常进行捕获,然 ...

  4. SpringBoot学习之SpringBoot执行器

    在以往的分布式开发当中,各个服务节点的监控必不可少.监控包含有很多方面,比如说:内存占用情况,节点是否健康等.在spring-boot会给我们提供相关资源监控叫做spring-boot-actuato ...

  5. SpringBoot编写自定义的starter 专题

    What’s in a name All official starters follow a similar naming pattern; spring-boot-starter-*, where ...

  6. Springboot的static和templates区别

    static和templates部分参考博客:https://blog.csdn.net/wangb_java/article/details/71775637 热部署参考博客:https://www ...

  7. SpringBoot 之Actuator.

    一.Actuator 介绍 Actuator 是 SpringBoot 项目中一个非常强大一个功能,有助于对应用程序进行监视和管理,通过 restful api 请求来监管.审计.收集应用的运行情况. ...

  8. Docker和jenkins实现springboot自动部署

    准备: 一个springboot项目.一台虚拟机(centos 7). 安装: linux安装docker 更新yum:yum update 下载docker: yum –y install dock ...

  9. 零基础IDEA整合SpringBoot + Mybatis项目,及常见问题详细解答

    开发环境介绍:IDEA + maven + springboot2.1.4 1.用IDEA搭建SpringBoot项目:File - New - Project - Spring Initializr ...

随机推荐

  1. python基础之初识python

    Python的发展史 1989年圣诞节期间,吉多·范罗苏姆为了打发时间,开发了python这门语言.真他妈牛逼. Python崇尚优美.清晰.简单,是一门优秀并广泛使用的语言.2007年在TIOBE榜 ...

  2. 解决 WP迁移后出现的404错误

    项目迁移 WordPress 后仅首页正常,其它页面全部 404.时隔一年,再度遇到这问题,总结和梳理一下. 1.想办法登录后台,刷新一次“设置”中的“固定链接”.比如换成默认后保存,再设回原先设置并 ...

  3. Vmware vSphere常见问题及解决办法

      Vmware vSphere常见问题及解决办法 日期:2012-6-29来源:51cto Vmware vSphere 12 1. 虚拟机文件被锁,无法正常 power on 故障状态: 启动虚拟 ...

  4. sonarQube Github pull request扫描代码

    参考官方地址:https://docs.sonarqube.org/display/PLUG/GitHub+Plugin 运行环境:sonarQube6.2 + sonarScanner2.8 近来, ...

  5. [mysql] 添加用户,赋予不同的管理权限

    增加新用户格式:grant 权限 on 数据库.* to 用户名@登录主机 identified by “密码”如,增加一个用户user1密码为password1,让其可以在本机上登录, 并对所有数 ...

  6. HDU 多校1.10

  7. 欧拉图和欧拉圈-Play On Words(UVa10129)

    欧拉路和欧拉圈,简言之就是,从无向图的一个结点出发,走一条路/圈,每条边恰好经过一次,即一笔画问题 欧拉定理:一个无向图最多只有两个奇结点,那么我们就从一个奇结点出发,到另一个结点为之,一定有一条欧拉 ...

  8. POJ 1236 Network Of Schools (强连通分量缩点求出度为0的和入度为0的分量个数)

    Network of Schools A number of schools are connected to a computer network. Agreements have been dev ...

  9. 【块状树】【LCA】bzoj1787 [Ahoi2008]Meet 紧急集合

    分块LCA什么的,意外地快呢…… 就是对询问的3个点两两求LCA,若其中两组LCA相等,则答案为第三者. 然后用深度减一减什么的就求出距离了. #include<cstdio> #incl ...

  10. Ubuntu 14 中 VirtualBox发生错误Kernel driver not installed (rc=-1908)

    宿主系统是Ubuntu 14,在VirtualBox中安装 CentOS 6.5 时,提示如下错误: Kernel driver not installed (rc=-1908) 网友提供的解决方案: ...