读取资源文件

@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. opencv inrange 和 mix

    opencv inrange: http://blog.csdn.net/xiaoyufei117122/article/details/53572904 http://blog.csdn.net/w ...

  2. 十个技巧快速优化你的Laravel 5 程序

    性能一直是 Laravel 框架为人诟病的一个点,所以调优 Laravel 程序算是一个必学的技能. 接下来分享一些开发的最佳实践,还有调优技巧,大家有别的建议也欢迎留言讨论. 这里是简单的列表: 配 ...

  3. React入门 (2)—实现微博展示列表

    前言 如果从来不了解React先看前篇React入门 (1)-使用指南(包括ES5和ES6对比). 本文为了能将前篇学到的react知识学以致用,做了一个类似微博展示列表的demo.使用的是ES6+R ...

  4. (十五)mysql中间件MyCAT实现

    1)拓扑如下和实现目标 写操作:都在master 读操作:在slave1上 当master1挂了,写操作自动切换到master2上 当master2挂了,写操作自动切换到master1上 2)Myca ...

  5. 从dao层查出的数据到页面时数值都是零的异常

    异常问题: IllegalArgumentException: argument type mismatch at cn.tedu.utils.BeanListHandler.handle(BeanL ...

  6. 4、Django实战第4天:xadmin快速搭建后台管理系统

    Django默认为我们提供了后台管理系统admin, urls.py中配置的第一条就是访问后台管理系统admin的 urlpatterns = [ url(r'^admin/', admin.site ...

  7. [BZOJ 4033] 树上染色

    Link: BZOJ 4033 传送门 Solution: 此题用到了计算贡献的方法, 将 多条路径的路径和  $->$ $\sum_{i=1}^{n-1} w[i]*cnt[i]$ 这样我们由 ...

  8. jdk8中Spliterator的作用

    文章前半部分转自:https://blog.csdn.net/lh513828570/article/details/56673804 之前的时候看集合部分源码没看完,今天又翻了一下,看到了个东西sp ...

  9. 【R笔记】日期处理

    R语言学习笔记:日期处理 1.取出当前日期 Sys.Date() [1] "2014-10-29" date() #注意:这种方法返回的是字符串类型 [1] "Wed O ...

  10. hadoop FileSplit

    /** A section of an input file. Returned by {@link * InputFormat#getSplits(JobContext)} and passed t ...