In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article focuses on "how to create a project in Java Spring Cloud". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to create a project with Java Spring Cloud".
0. Preface
The project is managed and built using Maven, so Maven needs to be pre-configured.
1. Create a project
First create a pom.xml file and add the following:
4.0.0
Club.attachie
Nature
Pom
${revision}
1.0-SNAPSHOT
POM full name project object model, that is, the project object model, it is the maven project annotation file, in XML format, the name is pom.xml. This file is used to manage source code, configuration files, developer information and roles, problem tracking system, organization information, project authorization, project address, and dependencies.
Pom files are so important to maven projects that a maven project can be without any other files and content, but absolutely not without pom.xml files.
1.1 Project Information
The pom file contains the basic information about the project:
GroupId Organization name
ArtifactId Project name
Version version number
1.2 use placeholders
We use a lot of project version numbers in pom, and sometimes we use other constants. If the constant distribution is relatively scattered, it is not conducive to our maintenance and management. At this point, placeholders, or attributes, are introduced. We declare the required constants in the properties node:
1.0-SNAPSHOT
This form is similar to declaring a variable
Revision=1.0-SNAPSHOT
When you need this variable, use it with ${revision}.
two。 Project structure layering
In an industrial project, we need to make a reasonable layering of the project. This is conducive to development and post-maintenance.
So, first add these three directories under the root directory:
Common is used to store some public bags.
The parent package where the activities business module is located
Manager is used to store some Spring Cloud management tools, such as Spring boot admin, Spring Cloud Gateway, etc.
Add the pom.xml file in three directories, and add:
4.0.0
Club.attachie
The respective project name, which is recommended as the directory name
Pom
${revision}
Club.attachie
Nature
${revision}
And modify their respective artifactId.
Then register to the pom.xml in the root directory and mark the three projects as subprojects.
Common
Activities
Manager
Then run:
Mvn clean install
Check to see if the configuration is wrong.
3. Introduce public dependence
Spring boot and Spring Cloud have established corresponding dependency packages so that we don't have to worry too much about some common projects conflicts with Spring boot and Spring Cloud versions in the development process.
First declare the introduced Spring boot version number and Spring Cloud version number in the pom.xml file in the root directory:
2.2.5.RELEASE
Hoxton.SR3
Create a dependency management node and add Spring boot and Spring Cloud dependency packages:
Org.springframework.boot
Spring-boot-dependencies
${spring-boot.version}
Pom
Import
Org.springframework.cloud
Spring-cloud-dependencies
${spring-cloud.version}
Pom
Import
All the three-party packages that need to be used in the subpackages should be managed by the pom.xml in the root directory, and the managed packages will be placed under the dependencyManagement > > dependencies node.
To use dependencies in your project, add the following nodes under the project node of the pom.xml file. If you already have one, you can ignore it, and note that it is not under dependencyManagement.
Try adding the lombok package (this is a famous package in Java that omits the creation of methods such as get/set in Java).
Org.projectlombok
Lombok
The version number is not declared because the package is already managed by spring-boot-dependencies. So we can just introduce it here.
At this point, I believe you have a deeper understanding of "how to create a project in Java Spring Cloud". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.