Subvert Java application development with spring boot

Source: Internet
Author: User

Java Development Overview:

The use of Java for Web application development has been around for nearly 20 years, from the original Servlet1.0 to the present so many frameworks, libraries and the entire ecosystem. After such a long period of development, Java, as a mature language, has evolved a very mature ecosystem, which is why many companies use Java as the mainstream language for server-side development, and why Java has maintained a very active user base. However, this ecosystem is complex, and a very simple Java Web application can be applied to the following technologies:

Java development is divided into two camps, one of which is the Java EE faction represented by Oracle, which is the official reference standard for web development. Among the key technologies are servlet, EJB, JMS, JSF, JDBC/JPA, JAXB, Jax-WS, etc. The other camp is the spring camp, which is represented by the open source community and pivotal, with key technologies such as the spring Framework, Spring MVC, Spring Data, spring security, and so on.

Spring has evolved into a mainstream framework for Java application development from the very beginning as a dependency injection of bean container. Java EE is discarded by many Java programmers because of its bloated, complex, and hard-to-use structure. CDI (Context Dependency injection) was introduced from Java EE6, and Java EE's design philosophy was very academic, and Gavin King was out of the industry's needs, making Java EE Development very complex. JSF even criticized the father of Java James Gosling. Instead, in the spring community, more and more modern application development methodologies are being incorporated to form different spring projects.

What is spring Boot?

Spring Boot is a community feedback-driven project. Spring boot can be said to be one of the most influential projects in spring and the entire Java community for at least the last 5 years. Spring boot mainly contains the following features:

    • Embed Tomcat, jetty, or undertow directly as a servlet container. After that, you never have to package the application into a war and upload it to application server.

    • Starter POM is available for easy package management, greatly reducing the jar hell or dependency hell

    • Automate the configuration of the spring framework, saving programmers a lot of time and effort, allowing programmers to focus on writing business logic code

    • No third-party systems are required, and Spring boot comes with program state information and health status that can be used in the production environment. It also allows the application to read external configuration information very easily.

    • No automatic generation of any code is required at all. No need to use XML to configure the framework

Why is spring boot disruptive?

Why is spring boot disruptive? Because it revolutionized the Java application development paradigm. We used to do spring application development, to know what classes to configure for Hibernate and spring to work together, to know how to configure the view resolver to control which template for the view layer display. After writing a lot of code, I found that we were only dealing with the configuration of the spring framework itself, and no business logic was written at all. After development, we also consider the issue of deployment, not to mention deploying to very cumbersome application servers such as WebSphere, WebLogic or JBoss, even if deployed to a lightweight container such as Tomcat or jetty, we need 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, there are often conflicts. Even if we have worked hard to solve these problems, after the successful deployment of the program, it is difficult for us to understand the running state of the program. It's possible that we're going to configure a lot of third-party tools to know how the application is running, what the parameters are, and what the environment variables are. Although spring has helped us solve the problem of dependency injection, simplifying some MVC processes, the spring framework itself integrates a growing number of things that make it increasingly difficult to configure and maintenance costs to rise in a straight line. Many times Java programmers see Python, Ruby or JavaScript programmers knocking on several commands to install some libraries, and then simply tapping a few lines of code, introducing some frameworks like flask, and then just a simple API to run. At this point the Java programmer may still be studying which library to use in MAVEN and how to configure it in the code. The expression in our hearts must be this:

(At this time Java Programmer Psychological Shadow area)

The time has come for Java programmers to be elated!

Traditional Spring Development vs Spring boot application development

Next I'll compare traditional spring application development with spring boot application development with specific examples. If we develop a rest API for Hello World, the traditional spring development should do so.

1. If you are using MAVEN for package management, write Pom.xml as follows

As can be seen in order to write a simple Hello World REST API we introduced Spring Core, Spring Web, Spring Web MVC, Java Servlet and Jackson so many package dependencies. Imagine what a complex program this POM would become ...

2. Write Helloworldinitializer class as follows

This is already a very simple Java config, and the small partners of spring that were configured with XML before Servlet 3.0 are now expected to crash.

3. Writing Helloworldconfiguration class

Notice that we have no business logic in this class.

4. Really start writing Helloworldrestcontroller

5. Download Tomcat

6. Package deployment to Tomcat

7. Visit Localhost:8080/helloworld, you finally see Hello world ...

Write here I have tired feel not love ...

Then the old Java driver will take you through the spring boot charm:

1. Writing Pom.xml

Notice that we've only introduced a package dependency, and that the version is going to go with him.

2. Write the main function

We mark Helloworlddemoapplication class here as Springbootapplication, and Spring Boot will perform many automatic configurations based on this tag in the background, such as configuring MVC, configuring packet scanning, injecting the necessary classes, Inject auto-configured classes and so on.

Here the main function is a Java standard main function, which is equivalent to the application portal, the servlet container will find the portal at startup, start the spring container, complete the initialization.

3. Writing Helloworldrestcontroller

4. Launch the application directly without the need to deploy

5. Visit to see Hello World directly

Before the HelloWorld program for beginners to spend at least 10-20 minutes and so on, with Springboot, up to 3 minutes to finish HelloWorld not a dream.

Summarize

Here I simply explained to Springboot, springboot there are a lot of things worth in-depth discussion, it not only let us do Java development is simple and effective, more importantly, springboot completely subvert our understanding of Java development, let us first have a "The original Java development can do this" feeling. With Springboot, Java programmers can focus more on business logic and more agile development.

Learn Java students pay attention to!!!
The learning process encountered any problems or want to acquire learning resources, welcome to join the Java Learning Exchange Group number:184625948"Long Press copy" we learn java! together.

Subvert Java application development with spring boot

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.