zoukankan      html  css  js  c++  java
  • 【spring boot】使用@Value映射properties文件属性

    描述

    使用@Value映射properties文件属性到Java字段

    重点

    • 使用@PropertySource 注解指定*.properties文件位置;
    • 使用@Value进行注入;

    my.properties

    book.author=ssslinppp
    book.name=spring boot
    
    

    Java类

    package com.sssppp;
    
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.context.annotation.PropertySource;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    @PropertySource("classpath:my.properties")
    public class Ch522 {
    
    	@Value("${book.author}")
    	private String bookAuthor;
    	
    	@Value("${book.name}")
    	private String bookName;
    
    	@RequestMapping("/aa")
    	String index() {
    
    		return "book name is:" + bookName + " and book author is:" + bookAuthor;
    	}
    
    }
    
    
  • 相关阅读:
    69. 二叉树的层次遍历
    17. 子集(Subsets)
    33. N皇后问题(回溯)
    15. 全排列
    53. 数字组合 II
    135. 数字组合
    95. 验证二叉查找树
    88. 最近公共祖先
    245. 子树
    [python应用]python简单图片抓取
  • 原文地址:https://www.cnblogs.com/ssslinppp/p/6963870.html
Copyright © 2011-2022 走看看