zoukankan      html  css  js  c++  java
  • Spring boot初始

    1 创建pom.xml

      parent:org.springframework.boot  包含启动的依赖

    添加依赖,如 spring-boot-starter-web

    mvn dependency:tree 查看依赖

    mvn spring-boot:run  启动服务

    build添加:spring-boot-maven-plugin依赖

    mvn package:打包,生成可运行jar

    命令启动 java -jar target/myproject-0.0.1-SNAPSHOT.jar

    main方法为启动入口

    @RestController表示接受请求,并返回一个字符串,字符串就是response
    @EnableAutoConfiguration表示自动推测
    @RequestMapping作用在方法上,指定请求的路由
     
     
    <?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.3.RELEASE</version>
    	</parent>
    
    	<!-- Additional lines to be added here... -->
        <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>
    

      

    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) {
    		SpringApplication.run(Example.class, args);
    	}
    
    }
    

      

  • 相关阅读:
    How to extract msu/msp/msi/exe files from the command line
    Windbg and resources leaks in .NET applications 资源汇总
    [c# 20问] 3.String和string的区别
    [c# 20问] 2.如何转换XML文件
    [c# 20问] 1. 何时使用class与struct
    安装配置BITS上传服务
    The J-Link hardware debugging Eclipse plug-in
    swift material
    SCLButton
    ChatCell
  • 原文地址:https://www.cnblogs.com/yoyogis/p/10432488.html
Copyright © 2011-2022 走看看