IDEA用Maven创建SpringCloud(Finchley)的聚合项目以及踩过的坑

一.创建父项目

在这里插入图片描述

  • File–>New–>Project
  • –>Maven–>Create from archetype–>maven-archetype-quickstart-Next
  • –>GroupId={你的GroupId}–>AritifactId={你的ArtifactId}
  • –>Next–>Next–>Finish–>New Whindow

二.创建子项目

在这里插入图片描述

  • 右键点击项目名称–>New–>Module
  • 选中Spring Initializr–>Next
  • –>Group={主工程的GroupId}–>Aritifact={当前模块的ArtifactId}、
  • –>Next–>Next–>Finish
    这样一个主项目和子项目就创建好了
    在这里插入图片描述
    名称可能不同,可以删去多余的文件

三.配置Pom文件

1.父项目的pom文件

<?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>ymm.per</groupId>
  <artifactId>sell-parent</artifactId>
  <version>1.0-SNAPSHOT</version>
  <!--更改打包方式-->
    <packaging>pom</packaging>
  <name>sell-parent</name>
  
  <!--新增包含的子项目-->
  <modules>
      <module>eureka</module>
  </modules>




    
    <!--继承Spring Boot 2.0.8.RELEASE,省去一些版本的问题
		这里使用2.0.8.RELEASE,要有相应的SpringCloud版本,具体请查看官网
-->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.8.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <!--配置参数-->
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <!--指定SpringCloud的版本-->
        <spring-cloud.version>Finchley.SR2</spring-cloud.version>
        <junit.version>4.12</junit.version>
    </properties>




    <!--Spring Cloud 版本序列配置-->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <!--仓库配置-->
    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>


<!--IDEA自动生成的插件-->
  <build>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-jar-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
        <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
        <plugin>
          <artifactId>maven-site-plugin</artifactId>
          <version>3.7.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-project-info-reports-plugin</artifactId>
          <version>3.0.0</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

2.子项目pom文件

<?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>ymm.per</groupId>
    <artifactId>eureka</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>eureka</name>
    <description>Demo project for Spring Boot</description>

	<!-- 继承父项目-->
    <parent>
        <groupId>ymm.per</groupId>
        <artifactId>sell-parent</artifactId>
        <version>1.0-SNAPSHOT</version>
        <relativePath/>
    </parent>

	<!-- 根据需求配置一些依赖
	这里有一个大坑
	从Dalston版本到Finchley,依赖的名称是不一样的,
	具体可以看http://blog.51cto.com/honly/2156583?source=dra
	-->
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

四.启动子项目

  • 在主启动类上加上注解 @EnableEurekaServer
@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication {

    public static void main(String[] args) {
        SpringApplication.run(EurekaApplication.class, args);
    }

}
  • application.yml 文件配置
	 eureka:
	   client:
	    defaultZone: localhost:8080/eureka
  • 启动主配置类
    在这里插入图片描述
    看到这个界面就成功啦
发布了12 篇原创文章 · 获赞 22 · 访问量 2万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览