To understand the spring-boot of this technique, you should know Spring-boot's core profile application.properties, and of course you can customize the profile **.properties information through annotations.
I. Reading the contents of the core profile information Application.properties
A core profile is a application.properties or application.yml configuration file that is in the resources root directory, and there are two ways to read the two configuration files, which are simpler.
(1) The core configuration file Application.properties content as follows:
[Java] view plain copy Test.msg=hello World Springboot
(1) mode one: Use @value method (commonly used)
[Java]View plain copy package Solin.controller; Import Org.springframework.beans.factory.annotation.Value; Import org.springframework.web.bind.annotation.RequestMapping; Import Org.springframework.web.bind.annotation.RestController; @RestController public class Webcontroller {@Value ("${test.msg}") Private String msg; @RequestMapping ("/index1") public String index1 () {return "way one:" +MSG; Note: The ${} in @value contains the key names in the core configuration file. Adding @restcontroller on the controller class indicates that all views in this class are displayed in JSON, similar to adding @responsebody to the view method.
Access: http://localhost:8088/index1: "Way One: Hello World Springboot"
(2) mode two: Use Environment way
[Java] View plain copy package solin.controller; import org.springframework.beans.factory.annotation.autowired; import org.springframework.beans.factory.annotation.value; import org.springframework.core.env.environment; import org.springframework.web.bind.annotation.requestmapping; import org.springframework.web.bind.annotation.restcontroller; @RestController public class webcontroller { @Autowired private Environment env; @RequestMapping ("/index2") public String Index2 () { return "mode two:" +env.getproperty (" Test.msg ");     } &NBSp NOTE: This approach relies on injection evnironment to complete, adding @autowired annotations on the created member variable private environment env to complete dependency injection, and then using Env.getproperty ("Key Name ") to read the corresponding value.
Access: Http://localhost:8088/index2: "mode two: Hello World Springboot"
(2) The core configuration file Application-dev.yml content as follows:
[Java] view plain Copy #--** Bank configuration file path start
Czb
Configpath:/usr/local/czbconfig/config.properties
#-Zhejiang merchant Bank related configuration file path end application*.yml Core configuration file, also read its contents in the above two ways. For example: The following figure is used to read: