美文网首页
springBoot测试1

springBoot测试1

作者: 紫玥迩 | 来源:发表于2017-04-19 10:07 被阅读16次

    Eclipse安装spring-tool-suite插件
    用于构建微服务
    Spring boot starter
    WebJars主官网

    pom.xml

    <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.yue.practise</groupId>
      <artifactId>springboot</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      
      <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.4.3.RELEASE</version>
      </parent>
    
      <name>springboot</name>
      <url>http://maven.apache.org</url>
    
      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      </properties>
    
      <dependencies>
        <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
      </dependencies>
    <build>
        <plugins>
            <!-- 创建一个完全自包含的可执行jar文件 -->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
    </project>
    

    A.java

    package com.yue.practise.springboot;
    
    import java.util.Date;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    @EnableAutoConfiguration
    public class A {
    
        @RequestMapping("/")
        String home(){
            return "hello world "+new Date();
        }
        
        public static void main(String[] args) {
            SpringApplication.run(A.class, args);
        }
    }
    

    mvn spring-boot:run
    http://localhost:8080/

    Paste_Image.png

    mvn package
    在target下看到jar包,cmd下运行

    Paste_Image.png
    java -jar springboot-0.0.1-SNAPSHOT.jar
    

    启动成功,http://localhost:8080/

    Paste_Image.png

    ctrl+c退出

    1. 不继承spring-boot-starter-parent
    <dependency>
                <!-- Import dependency management from Spring Boot -->
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>1.4.0.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
    
    1. 热部署
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
       </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork>
                </configuration>
            </plugin>
       </plugins>
    </build>
    

    相关文章

      网友评论

          本文标题:springBoot测试1

          本文链接:https://www.haomeiwen.com/subject/pbqgattx.html