Springboot First Project "Create 1"

Source: Internet
Author: User

1.new project, without checking the create from archetype, select directly

2.next Next

In maven dependency management, uniquely identifying a dependency is made up of three properties of the dependency, namely GroupID, Artifactid, and version. These three properties can uniquely identify a component (Jar package or war package). GroupID and Artifactid are designed to guarantee the uniqueness of the project.

What exactly does reference to GroupID and Artifactid in maven mean?

groupId: generally divided into multiple segments, the first segment is domain (org: nonprofit, com: business organization, CN: China). The second paragraph is the company name, the third paragraph is the company internal department, such as QA.

Artifactid: project name

Version: Snapshot and official versions. The main difference between the snapshot version and the official version is that there are different mechanisms for obtaining these dependencies locally.

    • official version : If you rely on the official version of a library, the build will be in the warehouse first to find if there is already , if not only to remote pull
    • Snapshot: Depending on the snapshot library, each time you build a project , you pull the version that it relies on remotely. When configuring Maven's repository, there is a configuration item that configures the frequency of lookups to the remote repository for the snapshot version. There are four kinds of frequencies, namely always, daily, interval, never. [] (./mavenauto.jpg)

3.pom.xml Configuration

    • Configure the version information in the properties, which can then be used ${java-version} to use the version number ' XML 1.8 '
    • Configure the dependent Jar package ' xml Com.wacai wacai-boot-starter-web '
    • The address of the snapshot snapshot library and release publishing library is configured in the Distributionmanagement segment, primarily the configuration of the ID and URL, which can be configured to be published via MVN deploy "XML deployment Internal repository for releases http://repo.caimi-inc.com/nexus/content/repositories/releases/"
    • Parent: Configures specific information for the inherited parent project, which can inherit configuration information from the parent project, such as dependencies "' XML Com.wacai wacai-boot-starter-parent 1.1.0 '
    • Build dependencies on plugins ' ' XML org.springframework.boot spring-boot-maven-plugin '
    • Resource configuration: Also configured in Build. Without compiling, it is a properties or XML configuration file that will tend to copy the resource file from the source path to the specified destination path "XML Meta-inf/plexus false ${basedir}/src/main/plexus" during the build process Configuration.xml **/*.properties ""

4. Project Structure

    • Create a Java directory under Src-main and right-click to select Mark directory as sources root
    • Create the package in the Java directory, the package name should be all lowercase, the package name prefix is GroupId.artifactId.XXX
    • Create a class under package Main, as a program entry
    • Target is to store the compiled file

5. Add Code

    • Add a main function to the main class
1  PackageCn.zll.testproject.controller;//This is going to be the name of your package.2 Importorg.springframework.boot.SpringApplication;3 Importorg.springframework.boot.autoconfigure.SpringBootApplication;4 //add note springbootapplication, which is a composite annotation that contains the following three:5 //@Configuration: Represents the Springboot configuration file class for this class. 6 //@EnableAutoConfiguration: Indicates that the springboot default configuration is loaded automatically when the program starts7 //@ComponentScan: Indicates that the program is started, automatically scans all classes under the current package and sub-packages8@SpringBootApplication Public classMain {9      Public Static voidMain (string[] args) {Ten         //Create a springapplication OneSpringapplication app =NewSpringapplication (Main.class);  A App.run (args); -     } -}
View Code
    • Create a controller package under the name of the package and add a class Indexcontroller
1  PackageCn.zll.springboottest.controller;2 ImportOrg.springframework.stereotype.Controller;3 Importorg.springframework.web.bind.annotation.RequestMapping;4 ImportOrg.springframework.web.bind.annotation.RequestMethod;5 6 //using controller annotations as controllers7 @Controller8  Public classIndexcontroller {9     //GET request for intercept/path, return content in Index.htmlTen@RequestMapping (value = "/", method =requestmethod.get) One      PublicString Index () { A         return"Index";  -     }  -}
View Code
    • Add templates under Resources and add index.html documents
      • Note: This requires adding a dependency ' xml Org.springframework.boot spring-boot-starter-thymeleaf ' in Pom.xml

6. Implementation

Right-click Main class, directly run-> open the browser, enter the localhost:8080, you can access

Springboot First Project "Create 1"

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.