foreword
In the recently analyzed and written SpringBoot source code analysis ( Interviewer: Tell me about the startup process of Springboot (50,000 words analysis startup process) ), I left myself a ConversionService
homework about the use of it, so I will make up the homework.
use source
My example of this conversion service here is very simple. It is to convert the number of String to Integer. The method of use comes from the source code. This figure is also in the B.2.1 processing context in the source code analysis article I wrote. This comment is from
env Take it ConversionService
, what is env? It is the abbreviation of the environment. In the section of analysis
A.6.1 Obtaining or creating environment variables, it mentions the relationship between the classes of several environment variables in the source code:
code example
@Test
public void testConversionService(){
AbstractEnvironment se = new StandardServletEnvironment();
AbstractEnvironment se1 = new StandardEnvironment();
StandardServletEnvironment se2 = new StandardServletEnvironment();
StandardEnvironment se3 = new StandardEnvironment();
ConfigurableConversionService conversionService = se.getConversionService();
Integer convert = conversionService.convert("111", Integer.class);
System.out.println(convert);
}
Combining the above code with the previous class diagram about environment variables, what we can new is mainly StandardServletEnvironment
, StandardEnvironment
, among which se1 to se3 can be used.
In fact, I haven't thought about what kind of business will use this kind of conversion in the business I usually contact. Let's prepare it first, in case it can be used in the future! ! !
-------------The more you know, the more you don't know----------------