


How to solve the problems of SpringBoot official website construction and quick startup
SpringBoot Overview
SpringBoot
is a brand new framework provided by the Pivotal team and is designed to be used with To simplify the initial construction and development process of Spring applications.
Everyone has experienced the SpringBoot
program. Let’s look back and see what the main function of SpringBoot
is to simplify the construction and development process of Spring
.
OriginalSpring
There are the following problems in environment construction and development:
Cumbersome configuration dependencies
Settings Cumbersome
SpringBoot
The advantage of the program happens to be automatic configuration for the shortcomings of Spring
. This is used to solve the problem of cumbersome program configuration in
Spring
- ##starting dependencies. This is used to solve
Spring
the problem of cumbersome program dependency settings
- auxiliary functions (built-in server,...). When we started the
SpringBoot
program, we neither used the local
tomcatnor the
tomcatplug-in, but used the
SpringBootbuilt-in server.
SpringBoot
Spring Initializr The
pom.xml configuration file of the
Maven project created in the
method automatically generates many dependencies containing starter
, as shown below
These dependencies are startup dependencies. Next, let’s explore how they are implemented.
Exploring the parent project
From the above file, we can see that a parent project is specified. We enter the parent project and find that another parent project is specified in the parent project, as shown in the figure below
Then enter the parent project. In this project, we can see the configuration content structure as shown below
The properties
tag in the above picture defines the versions that each technical software depends on, which avoids us considering version compatibility issues when using different software technologies. In properties
we find the versions of servlet
and mysql
as shown below
dependencyManagement# The ## tag is for dependency version locking, but the corresponding dependency is not imported; if our project needs that dependency, we only need to introduce the
groupid and
artifactId of the dependency. There is no need to define the
version .
build tag also locks the plug-in version, as shown below
After configuring pom.xml, it is not difficult to understand why none of our project’s dependencies are configured
version.
pom.xml in the project we created
pom.xml and you will find that it introduces the following dependencies
spring-web and
spring-webmvc are dependent on each other. This is why our project can still use the annotations in
springMVC without relying on these two packages.
spring-boot-starter-tomcat. From the name, we can basically confirm that
tomcat is internally dependent, so our project can start normally.
starter
Common project names in SpringBoot
define all project coordinates used by the current project to reduce dependency configuration
parent
- The projects to be inherited by all
SpringBoot
projects define several coordinate version numbers (dependency management, not dependency) to reduce dependencies Conflicting Purpose
spring-boot-starter-parent
(2.5.0) andspring-boot-starter-parent
(2.4.6) have a total of 57 coordinates Different versions
Actual development
When using arbitrary coordinates, only write G and A in GAV, V is provided by SpringBoot
G:groupid
A:artifactId
V:version
If a coordinate error occurs, specify the version again (be careful of version conflicts)
Program startup
Every SpringBoot
program created contains a class similar to the following. We call this class the boot class
@SpringBootApplication public class Springboot01QuickstartApplication { public static void main(String[] args) { SpringApplication.run(Springboot01QuickstartApplication.class, args); } }
Note:
SpringBoot
When creating a project, use the jar packaging methodSpringBoot
The boot class is the entry point of the project. Running themain
method can start the project
because we configured ## in pom.xml
#spring-boot-starter-web depends on it, and this dependency knows through previous learning that it depends on
tomcat, so running the
main method can use
tomcat Start our project.
tomcat server, can we use
jetty# instead of tomcat
## Server, jetty
When we maven
are advanced, we will talk about the server used by maven
private servers. To switch the web
server, you need to exclude the default tomcat
server. How to exclude it? Using the exclusion
tag <pre class='brush:php;toolbar:false;'><dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<artifactId>spring-boot-starter-tomcat</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency></pre>
Now can we run the bootstrap class? Try running it. The printed log information is as follows
The program stopped directly. Why? That's because if the
server is excluded, there will be no server in the program. So at this time not only the tomcat
server must be excluded, but also the jetty
server must be introduced. In pom.xml
, because the starting dependency of jetty
is <pre class='brush:php;toolbar:false;'><dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency></pre>
, run the boot class again. You can see in the log information that
Server
Summary:By switching the server, it is not difficult for us to find that we are using SpringBoot
Comparison between spring and springboot
When changing technology, you only need to import the starting dependencies of the technology.
After we finished the introductory case in the previous article, we can find that there is a big difference between the two:
- Spring
The coordinates in the program need to be written by yourself, and there are many coordinates
- SpringBoot
The coordinates in the program are automatically generated by checking when we create the project
- Spring
The program needs to write this configuration class by itself. Everyone has written this configuration class before, and it must feel very complicated
- SpringBoot
The program does not need to be written by ourselves
- Spring/SpringMVC
The configuration class of the program needs to be written by yourself. The
SpringBoot
program does not need to be written.
Spring Initializrbased on Idea requires an Internet connection to quickly build the
Official website construction projectSpringBoot
project.
The reason why the
SpringBoot project can be quickly built in the entry case is because Idea
uses the provided by the official website Quickly build the components of the SpringBoot
project. So how to build projects on the official website? Build through the following stepsEnter the SpringBoot official website
Enter the
SpringBoot official website and drag it to the bottom to see the following content
Then click
The hyperlink will jump to the following page
Does the content of this page look familiar? The interface is basically the same as the one we use
to quickly build the SpringBoot
project. Enter the corresponding information on the above pageSelect dependencies
Select
Spring Web You can click the ADD DEPENDENCIES... CTRL B
button in the upper right corner of the picture above , the following interface will appear<p><img src="/static/imghwm/default1.png" data-src="https://img.php.cn/upload/article/000/887/227/168376831282036.png?x-oss-process=image/resize,p_40" class="lazy" alt="How to solve the problems of SpringBoot official website construction and quick startup"></p>
<h4 id="生成工程">生成工程</h4>
<p>以上步骤完成后就可以生成 <code>SpringBoot
工程了。在页面的最下方点击 GENERATE CTRL + 回车
按钮生成工程并下载到本地,如下图所示
打开下载好的压缩包可以看到工程结构和使用 Idea
生成的一模一样,如下图
而打开 pom.xml
文件,里面也包含了父工程和 Spring Web
的依赖。
通过上面官网的操作,我们知道 Idea
中快速构建 SpringBoot
工程其实就是使用的官网的快速构建组件,那以后即使没有 Idea
也可以使用官网的方式构建 SpringBoot
工程。
SpringBoot工程快速启动
问题引入
以后我们和前端开发人员协同开发,而前端开发人员需要测试前端程序就需要后端开启服务器,这就受制于后端开发人员。为了摆脱这个受制,前端开发人员尝试着在自己电脑上安装 Tomcat
和 Idea
,在自己电脑上启动后端程序,这显然不现实。
我们后端可以将 SpringBoot
工程打成 jar
包,该 jar
包运行不依赖于 Tomcat
和 Idea
这些工具也可以正常运行,只是这个 jar
包在运行过程中连接和我们自己程序相同的 Mysql
数据库即可。这样就可以解决这个问题,如下图
那现在问题是如何打包呢?
打包
由于我们在构建 SpringBoot
工程时已经在 pom.xml
中配置了如下插件
<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin>
所以我们只需要使用 Maven
的 package
指令打包就会在 target
目录下生成对应的 Jar
包。
注意:该插件必须配置,不然打好的
jar
包也是有问题的。
启动
进入 jar
包所在位置,在 命令提示符
中输入如下命令
java -jar 包名.jar
执行上述命令就可以看到 SpringBoot
运行的日志信息
The above is the detailed content of How to solve the problems of SpringBoot official website construction and quick startup. For more information, please follow other related articles on the PHP Chinese website!

Java is widely used in enterprise-level applications because of its platform independence. 1) Platform independence is implemented through Java virtual machine (JVM), so that the code can run on any platform that supports Java. 2) It simplifies cross-platform deployment and development processes, providing greater flexibility and scalability. 3) However, it is necessary to pay attention to performance differences and third-party library compatibility and adopt best practices such as using pure Java code and cross-platform testing.

JavaplaysasignificantroleinIoTduetoitsplatformindependence.1)Itallowscodetobewrittenonceandrunonvariousdevices.2)Java'secosystemprovidesusefullibrariesforIoT.3)ItssecurityfeaturesenhanceIoTsystemsafety.However,developersmustaddressmemoryandstartuptim

ThesolutiontohandlefilepathsacrossWindowsandLinuxinJavaistousePaths.get()fromthejava.nio.filepackage.1)UsePaths.get()withSystem.getProperty("user.dir")andtherelativepathtoconstructthefilepath.2)ConverttheresultingPathobjecttoaFileobjectifne

Java'splatformindependenceissignificantbecauseitallowsdeveloperstowritecodeonceandrunitonanyplatformwithaJVM.This"writeonce,runanywhere"(WORA)approachoffers:1)Cross-platformcompatibility,enablingdeploymentacrossdifferentOSwithoutissues;2)Re

Java is suitable for developing cross-server web applications. 1) Java's "write once, run everywhere" philosophy makes its code run on any platform that supports JVM. 2) Java has a rich ecosystem, including tools such as Spring and Hibernate, to simplify the development process. 3) Java performs excellently in performance and security, providing efficient memory management and strong security guarantees.

JVM implements the WORA features of Java through bytecode interpretation, platform-independent APIs and dynamic class loading: 1. Bytecode is interpreted as machine code to ensure cross-platform operation; 2. Standard API abstract operating system differences; 3. Classes are loaded dynamically at runtime to ensure consistency.

The latest version of Java effectively solves platform-specific problems through JVM optimization, standard library improvements and third-party library support. 1) JVM optimization, such as Java11's ZGC improves garbage collection performance. 2) Standard library improvements, such as Java9's module system reducing platform-related problems. 3) Third-party libraries provide platform-optimized versions, such as OpenCV.

The JVM's bytecode verification process includes four key steps: 1) Check whether the class file format complies with the specifications, 2) Verify the validity and correctness of the bytecode instructions, 3) Perform data flow analysis to ensure type safety, and 4) Balancing the thoroughness and performance of verification. Through these steps, the JVM ensures that only secure, correct bytecode is executed, thereby protecting the integrity and security of the program.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download
The most popular open source editor

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Linux new version
SublimeText3 Linux latest version

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
