In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
1.idea to create SpringBoot project idea to create SpringBoot project should be too bad for many people to operate, but for beginners rookie, still need to explain. Open idea, then select Spring Initializr and click next directly. What needs to be said here is that there is a http://start.spring.io link on this interface, which is the official website link of SpringBoot. You can go to the official website of SpringBoot to create a project and import it into idea. This operation can be done by Baidu on its own. I want to operate directly in idea, so why go to the official website? Maybe it's too idle.
Then fill in the relevant information, including: Group (organization name) Artifact (is the project name, that is, the unique identifier of the project pair) Packaging:jar (packing method) Package (package name) Java Version (java version name)
Then click next to proceed to the next step
Then select the dependent module you need here, and then click next
Finally, select the local location of your project and click finish.
The project structure of the final SpringBoot created by the parent of the 2.SpringBoot project is as follows. Open the pom file, which defines the parent project of a SpringBoot project depending on holding down the Ctrl key and clicking the left mouse button.
After entering, it is important to look in the red box. Here, another parent parent is defined as spring-boot-dependencies. From the name, you can probably see that this is the dependency management of SpringBoot.
Then the description in the second red box is roughly as follows:
Defines the configuration of the compiled version of java 1.8 when you use the UTF-8 format to encode the packaging operation, and then under the red box is the configuration of the plug-in, and the filtering of resources.
Then Ctrl+ left mouse button click spring-boot-dependencies, as shown here is the dependency and dependent version management of SpringBoot. You can see that a bunch of version numbers mainly use properties and dependencyManagement to manage version numbers and dependencies. This is why we do not need to write version numbers when we introduce most of the dependencies in the SpringBoot project, because this is the dependency transmission relationship of maven. The parent has defined the version number for you. In addition, we can also use properties and dependencyManagement to customize our own version number in our own project, instead of using the version number provided for us by the parent. References are as follows: org.springframework.data spring-data-releasetrain Fowler-SR2 pom import org.springframework.boot spring-boot-dependencies 2.1.2.RELEASE pom import
Configuration file for 3.SpringBoot
The configuration file in the SpringBoot project can be in two formats, properties and yml, and the location of the file is as follows (priority from high to low, which means that the configuration file will be loaded first when the project loads jvm):
Under the root directory of the current project, under the config directory, under the root directory of the current project, under the resources directory, under the config directory, under the resources directory.
In addition to the default configuration file location given to us by SpringBoot, we can also specify the location of the configuration file ourselves. As shown in the figure, create a myconfig directory under the resources directory of the project, and then put the application.properties file in this directory
In addition, we can also specify the location of the configuration file when starting the project. This operation is mainly aimed at the packaged project, and the configuration file java-jar demo.jar-spring.config.location=classpath:/myconfig/ cannot be modified.
Finally, change the name of the application.properties/application.yml configuration file, because the name of our default configuration file can not be called this default name, for example, change it to myconfig.properties/myconfig.yml. As shown in the figure, spring.config.name=myconfig is used to specify the name of the configuration file when starting the project
In addition, when a project is already packaged, you can also specify the name of the configuration file through the following startup command
Java-jar demo.jar-- spring.config.name=myconfig
Finally, you can execute multiple commands at the same time, as follows:
Java-jar demo.jar-- configuration file syntax for spring,config.name=myconfig;spring.config.location=classpath:/myconfig/3.SpringBoot. Syntax for properties.
The syntax of properties is based on key and value. Keys and values are connected by an equal sign. For example, person.name= Li Yiyi injects the value in person.age=18properties, injecting the value through @ Value annotation. Note that the @ Component annotation should also be added to send the object to Spring container management @ Componentpublic class Person {@ Value ("${person.name}") private String name; @ Value ("${person.age}") private Integer age. / / omit getter/setter} type-safe attribute injection. In addition, SpringBoot provides another way of injection, which mainly solves the problem of writing @ Value@Component@PropertySource ("classpath:person.properties") @ ConfigurationProperties (prefix = "person") public class Book {private String name; private Integer age; / / omit getter/setter} yml syntax many times when many attributes are to be injected.
Compared with the syntax of properties, the syntax of yml is concise and clear, and the syntax is as follows: yml is divided by:
Injection of the value of the array: type: color:-white-black
This data is bound to a bean object, as shown in the following code:
ConfigurationProperties (prefix= "type") @ Componentpublic class Config {private List color = new ArrayList () public List getColor () {return this.color}}
When a single value is taken from the yml configuration file, the following
Type: color:white
Take a value
@ Value ("${type.color}") private String color
Please pay attention to more tutorials: non-subject classes, if you think the tutorials are helpful to you, please give me a like, thank you.
Finally, share a wave of java resources, including a full set of videos from entry to development of java, as well as 26 projects of java. The resources are relatively large, the size is about 290g, and the link is easy to fail. The way to get it is to follow the official account: non-subject class, and then reply: java project can be obtained, I wish you all a happy study.
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.