A preliminary study of spring's basic functions Overview Spring Start: Http://spring.io/guides building a RESTful Web Service This part is basically complete URL Access data return problem, its basic is more similar to the Django
This basically describes the basic process of spring running, that is, to listen to some parts of the package (in response) by corresponding annotations in the boot section of the Application.java Where springbootapplication can give instructions for monitoring multiple events (Web controller\components, etc.) Pack command mvn Clean compile mvn clean package scheduling Tasks Print out event information every 5s consuming a RESTful Web service the process implemented here is essentially the corresponding to the building a RESTful Web service, where the Resttemplate and the latter re
Stcontroller's comments correspond to the previous format for converting JSON to Java objects, which converts Java objects to JSON because the former is an object parsing, so the object key value format is given when parsing.
Here the application run function uses a lambda expression, where only a description of its assignment is given, and a lambda expression must be assigned an interface type if it is to be saved as an object.
The common use of thread as a calling method uses Runnable as an interface (calling the Run function) so that transformation assignments can be made.
such as: Runnable obj0 = (Runnable) ()->{system.out.println ("thired call");
New Thread (Obj0). Start ();
Object obj1 = (Runnable) ()->{system.out.println ("Fourth call.");
New Thread ((Runnable) obj1). Start (); So you can understand the following code: @Bean public Commandlinerunner Run (resttemplate resttemplate) throws Exception{return args-> {Quote Quote = Resttemplate.getforobject ("http://gturnquist-quoters.cfapps.io/
Api/random ", Quote.class);
Log.info (Quote.tostring ());
};
Where Commandlinerunner is an interface, its invocation of void run is defined by a lambda expression. The complete application class of the spring website is defined as @SpringBootApplication public class application {private static final Logger log = Logger
Factory.getlogger (Application.class);
public static void Main (String []args) {springapplication.run (application.class);
@Bean public resttemplate resttemplate (Resttemplatebuilder builder) {return builder.build ();
@Bean public Commandlinerunner Run (resttemplate resttemplate) throws exception{return args-> {
Quote Quote = Resttemplate.getforobject ("Http://gturnquist-quoters.cfapps.io/api/random", Quote.class);
Log.info (Quote.tostring ());
}; The actual implementation logic for removing the used @bean is: @SpringBootApplication public class AppliCation implements Commandlinerunner {private static final Logger log = Loggerfactory.getlogger (Application.class);
public static void Main (String args[]) {springapplication.run (application.class); @Override public void Run (String ... strings) throws Exception {resttemplate resttemplate = new Restte
Mplate ();
Quote Quote = Resttemplate.getforobject ("Http://gturnquist-quoters.cfapps.io/api/random", Quote.class);
Log.info (Quote.tostring ());
The obvious following form is easy to understand.
By observing the source can be found Springapplication.run is through the springapplication to Application.class initialization after the call run function, so the following code implements way is understandable.
For the first method, because Builder.build returns the corresponding instance for the factory function, it is generally used in @bean to call the return instance in the dependent class, except that the way it is returned is through the
The Lambda anonymous function body is returned to the interface Commandlinerunner, and the extrapolation is done by Java type inference because there is only one interface callback function. The process of calling args and its function body in an interface is determined by Commandlinerunner (see document accordingly), a bean should run when it is contained within a springapplicatio n means that springapplication and Commandlinerunner together determine the invocation of the statement block.
So the first code doesn't take advantage of the Bean's attributes