Ava development overview:
Using Java for web application development has a history of nearly 20 years, evolving step by step from the original Servlet1.0 to so many frameworks, libraries and entire ecosystems. After such a long period of development, Java, as a mature language, has also evolved into a very mature ecosystem. This is why many companies use Java as the mainstream language for server-side development, and why Java has always maintained a very active development trend. user group. However, this ecosystem is complex, and a very simple Java Web application may apply the following technologies:
Java development is divided into two camps, one is the Java EE camp represented by Oracle, and this is the Web The official reference standard developed. The core technologies include Servlet, EJB, JMS, JSF, JDBC/JPA, JAXB, JAX-WS, etc. The other camp is the Spring camp represented by the open source community and Pivotal. The core technologies include Spring Framework, Spring MVC, Spring Data, Spring Security, etc.
Spring started as a bean container for dependency injection and gradually developed into a mainstream framework for Java application development. Java EE has been abandoned by many Java programmers because of its bloated, complex, and difficult-to-use structure. CDI (Context Dependency Injection) has only been introduced since Java EE6, and the design ideas of Java EE are very academic. Gavin King and others are divorced from the needs of the industry, making Java EE development very complicated. JSF was even criticized by James Gosling, the father of Java. On the contrary, in the Spring community, more and more modern application development methods are being integrated into different Spring projects.
What is Spring Boot?
Spring Boot is a project driven by community feedback. Spring Boot can be said to be one of the most influential projects in Spring and even the entire Java community in at least the past five years. Spring Boot mainly includes the following features:
Directly embed Tomcat, Jetty or Undertow as a Servlet container. From now on, there is no need to package the application into a war and then upload it to the application server.
Provides starter POM, which can be very convenient for package management, greatly reducing jar hell or dependency hell
Automatically configures the Spring framework, saving programmers a lot of time and energy, allowing programmers to focus on The writing of business logic code does not require any third-party system. Spring Boot comes with program status information and health status that can be used in the production environment. At the same time, it allows applications to read external configuration information very conveniently
without any automatic code generation at all. There is no need to use xml to configure the framework
Why is Spring Boot disruptive?
Why is Spring Boot disruptive? Because it completely changes the model of Java application development. In the past, when we were developing Spring applications, we had to know which classes to configure to allow Hibernate and Spring to work together, and how to configure the view resolver to control which template displays the view layer. After writing a lot of code, I often find that I am only dealing with the configuration of the Spring framework itself, without writing a single line of business logic. After development is completed, we still need to consider deployment issues, not to mention deploying to very heavy application servers such as WebSphere, Weblogic or JBoss. Even if we deploy to lightweight containers such as Tomcat or Jetty, we need to know how to configure the container. , how to modify the configuration file, etc. And when multiple applications are deployed to the same Tomcat, conflicts often occur. Even if we spend a lot of effort to solve these problems, after the program is deployed successfully, it is difficult for us to understand the running status of the program. It is possible that we need to configure many third-party tools to know how the application is running, what parameters it has, and what the environment variables are. Although Spring has helped us solve the problem of dependency injection and simplified some MVC processes, the Spring framework itself has integrated more and more things, making it increasingly difficult to configure and maintenance costs have skyrocketed. Many times Java programmers see Python, Ruby or JavaScript programmers typing a few commands to install some libraries, then simply typing a few lines of code, introducing some frameworks such as flask, and then running a simple API directly. At this time, Java programmers may still be studying which library in Maven to use and how to configure it in the code. The expression in everyone's mind must be like this:
Traditional Spring development vs. Spring Boot application development
Next, I will compare 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 you use Maven for package management, write pom.xml as follows
As you can see above, in order to write a simple hello world REST API, we have introduced many package dependencies such as Spring Core, Spring Web, Spring Web MVC, Java Servlet and Jackson. You can imagine what this pom will look like for a more complex program. . .
2. Write the HelloWorldInitializer class as follows
This is already a very simple Java Config. Friends who used XML to configure Spring before Servlet 3.0 may have collapsed now.
3. Write HelloWorldConfiguration class
Notice that there is not a single line of business logic in our class. . .
4. Really start writing HelloWorldRestController
Use Spring Boot to subvert Java application development
I have been using Java for web application development for nearly 20 years, and it has evolved step by step from the original Servlet1.0 to so many now frameworks, libraries, and entire ecosystem. After such a long period of development, Java, as a mature language, has also evolved into a very mature ecosystem. This is why many companies use Java as the mainstream language for server-side development, and why Java has always maintained a very active development trend. user group.
Author: On the Self-cultivation of Coders Source: Tuiku|2016-10-14 14:16
Collection
Share
Overview of Java Development:
Using Java for web application development has been around for a long time With a history of 20 years, it has evolved step by step from the original Servlet 1.0 to so many frameworks, libraries and entire ecosystems. After such a long period of development, Java, as a mature language, has also evolved into a very mature ecosystem. This is why many companies use Java as the mainstream language for server-side development, and why Java has always maintained a very active development trend. user group. However, this ecosystem is complex, and a very simple Java Web application may apply the following technologies:
Java development is divided into two camps, one is the Java EE camp represented by Oracle, and this is Web development official reference standard. The core technologies include Servlet, EJB, JMS, JSF, JDBC/JPA, JAXB, JAX-WS, etc. The other camp is the Spring camp represented by the open source community and Pivotal. The core technologies include Spring Framework, Spring MVC, Spring Data, Spring Security, etc.
Spring started as a bean container for dependency injection and gradually developed into a mainstream framework for Java application development. Java EE is abandoned by many Java programmers because of its bloated, complex, and difficult-to-use structure. CDI (Context Dependency Injection) has only been introduced since Java EE6, and the design ideas of Java EE are very academic. Gavin King and others are divorced from the needs of the industry, making Java EE development very complicated. JSF was even criticized by James Gosling, the father of Java. On the contrary, in the Spring community, more and more modern application development methods are being integrated into different Spring projects.
What is Spring Boot?
Spring Boot is a project driven by community feedback. Spring Boot can be said to be one of the most influential projects in Spring and even the entire Java community in at least the past five years. Spring Boot mainly includes the following features:
Directly embed Tomcat, Jetty or Undertow as a Servlet container. From now on, there is no need to package the application into a war and then upload it to the application server.
Provides starter POM, which can be very convenient for package management, greatly reducing jar hell or dependency hell
Automatically configures the Spring framework, saving programmers a lot of time and energy, allowing programmers to focus on The writing of business logic code does not require any third-party system. Spring Boot comes with program status information and health status that can be used in the production environment. At the same time, it allows applications to read external configuration information very conveniently
without any automatic code generation at all. There is no need to use xml to configure the framework
Why is Spring Boot disruptive?
Why is Spring Boot disruptive? Because it completely changes the model of Java application development. In the past, when we were developing Spring applications, we had to know which classes to configure to allow Hibernate and Spring to work together, and how to configure the view resolver to control which template displays the view layer. After writing a lot of code, I often find that I am only dealing with the configuration of the Spring framework itself, without writing a single line of business logic. After development is completed, we still need to consider deployment issues, not to mention deploying to very heavy application servers such as WebSphere, Weblogic or JBoss. Even if we deploy to lightweight containers such as Tomcat or Jetty, we need to know how to configure the container. , how to modify the configuration file, etc. And when multiple applications are deployed to the same Tomcat, conflicts often occur. Even if we spend a lot of effort to solve these problems, after the program is deployed successfully, it is difficult for us to understand the running status of the program. It is possible that we need to configure many third-party tools to know how the application is running, what parameters it has, and what the environment variables are. Although Spring has helped us solve the problem of dependency injection and simplified some MVC processes, the Spring framework itself has integrated more and more things, making it increasingly difficult to configure and maintenance costs have skyrocketed. Many times Java programmers see Python, Ruby or JavaScript programmers typing a few commands to install some libraries, then simply typing a few lines of code, introducing some frameworks such as flask, and then running a simple API directly. At this time, Java programmers may still be studying which library in Maven to use and how to configure it in the code. The expression in everyone's heart must be like this:
(Please ask for the psychological shadow area of Java programmers at this time)
It's time for Java programmers to feel proud!
Traditional Spring development vs. Spring Boot application development
Next, I Traditional Spring application development and Spring Boot application development will be compared through specific examples. If we develop a Hello World REST API, traditional Spring development should do this.
1. If you use Maven for package management, write pom.xml as follows
As you can see above, in order to write a simple hello world For REST API, we have introduced many package dependencies such as Spring Core, Spring Web, Spring Web MVC, Java Servlet and Jackson. You can imagine what this pom will look like for a more complex program. . .
2. Write the HelloWorldInitializer class as follows
This is already a very simple Java Config. Friends who used XML to configure Spring before Servlet 3.0 have probably collapsed now.
3. Write HelloWorldConfiguration class
Notice that there is not a single line of business logic in our class. . .
4. Really start writing HelloWorldRestController
5. Download Tomcat
6. Package and deploy to Tomcat
7. Visit localhost:8080/HelloWorld, you finally see Hello World...
I have already written this I’m tired and don’t love anymore. . .
Next, the experienced Java driver will lead you to experience the charm of Spring Boot:
Writing pom. Just let it go
2. Write the main functionHere I just briefly explained SpringBoot. SpringBoot has a lot of things worthy of in-depth discussion. It not only makes our Java development simple and effective, but more importantly, SpringBoot has completely subverted our understanding of Java development, making it For the first time, we have the feeling of "it turns out that Java development can be done this way". With SpringBoot, Java programmers can focus more on business logic and conduct more agile development.