zoukankan      html  css  js  c++  java
  • Spring boot 官网学习笔记

    1. Creating the POM
      1. <?xml version="1.0" encoding="UTF-8"?>
        <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
            <modelVersion>4.0.0</modelVersion>
            
            <groupId>com.example</groupId>
            <artifactId>myproject</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            
            <parent>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-parent</artifactId>
                <version>2.1.1.RELEASE</version>
            </parent>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                </dependency>
            </dependencies>
        </project>
            
      2. 通过POM的dependencies 实现 Adding Classpath Dependencies
      3. 关于spring-boot-starter-parent:You should need to specify only the Spring Boot version number on this dependency. If you import additional starters, you can safely omit the version number.

    2. 使用 mvn dependency:tree  查看project dependencies
    3. 编写java代码
      1. src/main/java/Example.java
      2. import org.springframework.boot.*;
        import org.springframework.boot.autoconfigure.*
        import org.springframework.web.bind.annotation.*;
        
        @RestController
        @EnableAutoConfiguration
        public class Example{
            @RequestMapping("/")
            String home(){
                return "Hello World!";
            }
            public static void main(String[] args) throws Exception{
                SpringApplication.run(Example.class,args);
            }
        }
      3. @RestController and @RequestMapping annotations are Spring MVC annotations
      4. @EnableAutoConfiguration. This annotation tells Spring Boot to “guess” how you want to configure Spring, based on the jar dependencies that you have added. Since spring-boot-starter-web added Tomcat and Spring MVC, the auto-configuration assumes that you are developing a web application and sets up Spring accordingly.
      5. Starters and Auto-configuration

        Auto-configuration is designed to work well with “Starters”, but the two concepts are not directly tied. You are free to pick and choose jar dependencies outside of the starters. Spring Boot still does its best to auto-configure your application.

    4. Running the Example
      1. mvn spring-boot:run
    5. Creating an Executable Jar
      1. To create an executable jar, we need to add the spring-boot-maven-plugin to our pom.xml. To do so, insert the following lines just below the dependencies section:
      2. Spring Boot includes a Maven plugin that can package the project as an executable jar. Add the plugin to your <plugins> section if you want to use it, as shown in the following example:
      3. <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
        
        
        
        
        <?xml version="1.0" encoding="UTF-8"?>
        <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
            <modelVersion>4.0.0</modelVersion>
            
            <groupId>com.example</groupId>
            <artifactId>myproject</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            
            <parent>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-parent</artifactId>
                <version>2.1.1.RELEASE</version>
            </parent>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                    </plugin>
                </plugins>
            </build>
        </project>
            
      4. mvn package
      5. java -jar target/myproject-0.0.1-SNAPSHOT.jar
    6. 参考:https://docs.spring.io/spring-boot/docs/2.1.1.RELEASE/reference/htmlsingle/#getting-started-first-application
  • 相关阅读:
    vs2017 vs2019 打开cs文件提示无法识别的GUID格式
    A股和B股票的区别?
    选股:“均线是水,K线是舟,量是马达!”的选美理念!
    什么是K线?K线的详解!
    5日均线MACD
    炒股的常见技术指标
    选股票几大原则:趋势原则,强势原则,分批原则
    金融蝴蝶效应
    股市里的大户和散户
    期货平仓/强制平仓/爆仓-股市平仓建仓
  • 原文地址:https://www.cnblogs.com/jiangtao1218/p/10099255.html
Copyright © 2011-2022 走看看