SpringBoot will overthrow previous Java application development

It has been almost 20 years since Web application development was done using Java. It has evolved from the initial Servlet 1.0 step by step to so many frameworks, libraries, and the entire ecosystem. After such a long period of development, Java, as a mature language, has also evolved a very mature ecosystem. This is why many companies use Java as the mainstream language for server-side development, and why Java has always been very active. user group.

Java development overview:

It has been almost 20 years since Web application development was done using Java. It has evolved from the initial Servlet 1.0 step by step to so many frameworks, libraries, and the entire ecosystem. After such a long period of development, Java, as a mature language, has also evolved a very mature ecosystem. This is why many companies use Java as the mainstream language for server-side development, and why Java has always been very active. user group. However, this ecosystem is complex and a very simple Java Web application may be applied to the following technologies:

SpringBoot will overthrow previous Java application development

Java development is divided into two camps. One is the Java EE camp represented by Oracle. This is the official reference standard for Web development. The core technologies include Servlet, EJB, JMS, JSF, JDBC/JPA, JAXB, and JAX-WS. The other camp is the Spring camp represented by the open source community and Pivotal. The core technologies are Spring Framework, Spring MVC, Spring Data, Spring Security, and so on.

From the very beginning, Spring has become a mainstream Java application development framework as a dependency-injected Bean container. Java EE is abandoned by many Java programmers because of its bloated, complex, and difficult-to-use architecture. Since the introduction of Java EE6, CDI (Context Dependency Injection) has been introduced, and the design philosophy of Java EE has been very academic. Gavin King et al. have left the needs of the industry, making the development of Java EE very complicated. JSF even criticized James Gosling, the father of Java. On the contrary, in the Spring community, more and more modern application development methods have been integrated to form different Spring projects.

What is Spring Boot?

Spring Boot is a community feedback-driven project. Spring Boot is arguably one of the most influential projects in Spring and even the entire Java community in at least the past five years. Spring Boot mainly contains the following features:

1. Embed directly into Tomcat, Jetty or Undertow as a Servlet container. From then on, it is no longer necessary to package the application into a war and upload it to the application server.

2. Provides starter POM, which can be very convenient for package management, greatly reducing the jar hell or dependency hell

3. Automatically configure the Spring framework, saving programmers a lot of time and effort, allowing programmers to focus on the preparation of business logic code

4. No third-party system is required. Spring Boot comes with program status information and health status that can be used in the production environment. At the same time can make the application very convenient to read the external configuration information

5. No automatic generation of any code at all. Do not need to use xml to configure the framework

Why is Spring Boot subversive?

Why is Spring Boot subversive? Because it completely changed the Java application development model. In the past, we did Spring application development. We must know which classes are configured to let Hibernate and Spring work together. We must know how to configure view resolver to control which template is used to display the view layer. After writing a lot of code, I found out that I was only dealing with the configuration of the Spring Framework itself. I didn't write a single line of business logic. After the development is completed, we also need to consider the deployment problem, and do not say deploy to a very cumbersome application server, such as WebSphere, Weblogic or JBoss, even if deployed to a lightweight container such as Tomcat or Jetty, we have to know how to configure the container , how to modify the configuration file and so on. And when multiple applications are deployed to the same Tomcat, conflicts often arise. Even if we spent a lot of effort to solve these problems, after the successful deployment of the program, it is difficult for us to understand the operating status of this program. It is possible that we will configure many third-party tools to know how the application is running, what parameters it has, and what the environment variables are. Although Spring helps us solve the problem of dependency injection and simplifies some of the MVC processes, the Spring Framework itself integrates more and more things, making it more and more difficult to configure, and the maintenance costs are rising in a straight line. Many times Java programmers see Python, Ruby, or JavaScript programmers hitting a few commands to install some libraries, then simply typing a few lines of code, introducing frameworks such as flasks, and then running a simple API directly. At this time, Java programmers may still be studying which library to use in Maven and how to configure it in code. The expression in everyone's heart is definitely like this:

(At this time, the psychological shadow area of ​​Java programmers)

It's time for Java programmers to be proud!

Traditional Spring Development Versus Spring Boot Application Development

Next I will compare the traditional Spring application development and Spring Boot application development through specific examples. If we develop a Hello World REST API, traditional Spring development should do this.

1. If using Maven for package management, write pom.xml as follows

SpringBoot will overthrow previous Java application development

SpringBoot will overthrow previous Java application development

As you can see, in order to write a simple hello world REST API we have introduced so many package dependencies for Spring Core, Spring Web, Spring Web MVC, Java Servlet and Jackson. It can be imagined how a complicated program will become like this pom. . .

2. Write the HelloWorldInitializer class as follows

SpringBoot will overthrow previous Java application development

This is already a very simple Java Config. Configuring XML with XML before Servlet 3.0 is now estimated to have crashed.

3. Write HelloWorldConfiguration class

SpringBoot will overthrow previous Java application development

Notice that there is no business logic in our class. . .

4 really started to write HelloWorldRestController

SpringBoot will overthrow previous Java application development

5. Download Tomcat

6. Package deployment to Tomcat

7. Visit localhost:8080/HelloWorld and you finally see Hello World...

I haven’t loved it since I wrote it here. . .

The next old Java driver will lead you to feel the charm of Spring Boot:

Write pom.xml

SpringBoot will overthrow previous Java application development

SpringBoot will overthrow previous Java application development

Notice that we only introduced a package dependency, and the version will go with him.

2. Write the main function

We mark the HelloWorldDemoApplication class as SpringBootApplication. Spring Boot will do a lot of automatic configuration in the background according to this tag, such as configuring MVC, configuring package scanning, injecting necessary classes, injecting auto-configured classes, and so on.

Here the main function is a java standard main function, this is equivalent to the application entry, servlet container will find this entry at startup, start the Spring container, complete the initialization.

3. Write HelloWorldRestController

SpringBoot will overthrow previous Java application development

4. Start the application directly and do not need to deploy

Before the HelloWorld program took a minimum of 10-20 minutes for a novice, and with SpringBoot, getting HelloWorld up to 3 minutes is not a dream.

to sum up

Here I just briefly explained to SpringBoot, SpringBoot has a lot of things worthy of in-depth discussion, it not only allows us to do Java development becomes simple and effective, more importantly, SpringBoot completely subvert our understanding of Java development, let us The first time I had the feeling that "original Java development can do this". With SpringBoot, Java programmers can focus more on business logic for more agile development.

Liquid Crystal Display For Vehicle Use

Dongguan Yijia Optoelectronics Co., Ltd. , https://www.everbestlcdlcms.com