Spring boot quick build spring framework tutorial
Spring is an open source framework. Spring is a lightweight java development framework rising in 2003. It is derived from some concepts and prototypes described by rod Johnson in his book expert one on one J2EE development and design.
It is created to solve the complexity of enterprise application development. One of the main advantages of the framework is its layered architecture, which allows users to choose which component to use, and provides an integrated framework for J2EE application development. Spring uses basic JavaBeans to do things that previously could only be done by EJBs.
However, the use of spring is not limited to server-side development. From the perspective of simplicity, testability and loose coupling, any Java application can benefit from spring. The core of spring is inversion of control (IOC) and aspect oriented (AOP). In short, spring is a layered Java Se / EE full stack (one-stop) lightweight open source framework.
Spring boot is a new subproject of the spring framework for creating spring 4.0 projects. Its development began in 2013. Released in April 2014, 1.0 Version 0. It can automatically configure various spring components without relying on code generation and XML configuration files. Spring boot also provides recommended component configurations for common scenarios. Spring boot can greatly improve the development efficiency when using the spring framework. The following article will introduce spring boot in detail.
Spring boot includes the following features:
1. Create spring applications that can run independently. 2. It is directly embedded in Tomcat or jetty server and does not need to deploy war files. 3. Provide recommended base POM files to simplify Apache Maven configuration. 4. Automatically configure the spring framework according to project dependencies as much as possible. 5. Provide functions that can be used directly in the production environment, such as performance indicators, application information and application health check. 6. There is no code generation and no XML configuration file.
Create a new Maven function and copy the following code directly to POM In XML:
POM. From above It can be seen from the XML file that the application declares few dependencies. There is only one "org. Springframework. Boot: spring boot starter Web", rather than many dependencies like other spring projects. When you use the Maven command "MVN dependency: tree" to view the actual dependencies of the project, you will find that it contains dependencies such as spring MVC framework, slf4j, Jackson, hibernate validator and Tomcat. This is actually a combination of open source libraries recommended by spring for use in web applications.
Call the Java code of spring boot application, as follows:
Application. Java class is a simple web application that can run independently. Running the Java class directly will start an embedded Tomcat server running on port 8080. Visit“ http://localhost:8080 ”You can see "www.yoodb. Com" on the page Only two simple files are needed to start a web application running independently. There is no need to install an additional application server similar to tomcat, and there is no need to package it into a war file. You can start the application on the command line through "MVN spring boot: run".
In POM The "org. Springframework. Boot: spring boot Maven plugin" plug-in is added to the XML file. After adding the plug-in, when you run "MVN package" for packaging, it will be packaged into a jar file that can be run directly. You can run it directly by using "Java jar" command. To a great extent, it simplifies the deployment of applications, and only needs to install JRE to run.
The "@ enableautoconfiguration" annotation is used to enable spring boot to automatically configure the spring framework according to the dependencies declared by the application, reducing the workload of developers. The annotations "@ restcontroller" and "@ requestmapping" are provided by spring MVC to create rest services. These two annotations have nothing to do with spring boot itself.
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.