zoukankan      html  css  js  c++  java
  • SpringBoot2.0.2 不使用parent作为maven单继承方式操作 : org.springframework.boot : spring-boot-dependencies : 2.0.2.RELEASE

    1、pom配置方式
     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     3          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     4     <modelVersion>4.0.0</modelVersion>
     5 
     6     <groupId>com.springboot</groupId>
     7     <artifactId>quick_start</artifactId>
     8     <version>0.0.1-SNAPSHOT</version>
     9     <packaging>jar</packaging>
    10 
    11     <name>quick_start</name>
    12     <url>http://maven.apache.org</url>
    13     <description>Demo project for Spring Boot</description>
    14 
    15     <properties>
    16         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    17         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    18         <maven.compiler.source>1.8</maven.compiler.source>
    19         <maven.compiler.target>1.8</maven.compiler.target>
    20         <java.version>1.8</java.version>
    21     </properties>
    22 
    23     <dependencies>
    24         <!--不使用parent方式进行依赖,需要scope和type设置-->
    25         <dependency>
    26             <groupId>org.springframework.boot</groupId>
    27             <artifactId>spring-boot-dependencies</artifactId>
    28             <version>2.0.2.RELEASE</version>
    29             <scope>import</scope>
    30             <type>pom</type>
    31         </dependency>
    32 
    33 
    34         <dependency>
    35             <groupId>org.springframework.boot</groupId>
    36             <artifactId>spring-boot-starter-web</artifactId>
    37         </dependency>
    38 
    39         <dependency>
    40             <groupId>org.springframework.boot</groupId>
    41             <artifactId>spring-boot-starter-test</artifactId>
    42             <scope>test</scope>
    43         </dependency>
    44     </dependencies>
    45 
    46     <build>
    47         <plugins>
    48             <plugin>
    49                 <groupId>org.springframework.boot</groupId>
    50                 <artifactId>spring-boot-maven-plugin</artifactId>
    51             </plugin>
    52         </plugins>
    53     </build>
    54 
    55 
    56 </project>
    View Code

    2、实体类编写

     1 package com.springboot;
     2 
     3 import org.springframework.boot.SpringApplication;
     4 import org.springframework.boot.autoconfigure.SpringBootApplication;
     5 import org.springframework.context.ConfigurableApplicationContext;
     6 import org.springframework.context.annotation.Bean;
     7 
     8 /******************************
     9  * @Author : liuyang
    10  * @ClassName : QuickStartApplication
    11  * @Date : 2018 五月  20
    12  * @Time : 01:05:59
    13  * @Type : SpringBoot
    14  * @Version : 1.0
    15  * @Return :
    16  * @Description :
    17  *******************************/
    18 
    19 @SpringBootApplication
    20 public class QuickStartApplication {
    21 
    22     @Bean
    23     public Runnable createRunnable() {
    24 
    25         return () -> {
    26             System.out.println("Spring Boot is Run");
    27         };
    28 
    29     }
    30 
    31     public static void main(String[] args) {
    32         ConfigurableApplicationContext applicationContext = SpringApplication.run(QuickStartApplication.class,args);
    33         applicationContext.getBean(Runnable.class).run();
    34     }
    35 }
    View Code

    源码存放:
          需要将parent部分注释掉
            https://github.com/liushaoye/quick_start

    这个在官方文档上也有具体写:

                     https://docs.spring.io/spring-boot/docs/2.0.2.RELEASE/reference/htmlsingle/#boot-documentation

    仔细阅读这一段就是具体解答

  • 相关阅读:
    将博客搬至CSDN
    小啃机器学习(1)-----ID3和C4.5决策树
    然爸读书笔记(2014-12)----20个月赚130亿
    然爸读书笔记(2014-11)----小米的尖叫
    然爸读书笔记(2014-10)----Bootsrap用户手册
    然爸读书笔记(2014-9)----互联网思维到底是什么
    然爸读书笔记(2014-8)----结果第一
    论文阅读(2014-2)----The YouTube Video Recommendation System
    然爸读书笔记(2014-7)----平台战略
    扎克伯格谈Facebook创业过程
  • 原文地址:https://www.cnblogs.com/liuyangfirst/p/9062309.html
Copyright © 2011-2022 走看看