微服务的使用(一)

微服务的创建(一)

1 创建父工程项目 cloud-demo
微服务的使用(一)_第1张图片
项目结构
微服务的使用(一)_第2张图片
2 创建nacos-servereureka-server 服务 ,创建方式和上面一样

3 编写父工程的pom文件


<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.0modelVersion>
    
    <groupId>org.examplegroupId>
    
    <artifactId>cloud-demoartifactId>
    
    <version>1.0-SNAPSHOTversion>

    
    <packaging>pompackaging>
     
    <modules>
        <module>eureka-servermodule>
        <module>nacos-servermodule>
    modules>
    
    <parent>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-parentartifactId>
        <version>2.6.14version>
    parent>
    
    <properties>
        <maven.compiler.source>8maven.compiler.source>
        <maven.compiler.target>8maven.compiler.target>
        <java.version>1.8java.version>
        <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
        <spring-cloud.version>2021.0.6spring-cloud.version>
        <spring-cloud-alibaba.version>2021.0.4.0spring-cloud-alibaba.version>
        <lombok.version>1.18.26lombok.version>
    properties>
    
    <dependencyManagement>
        <dependencies>
        
            <dependency>
                <groupId>org.springframework.cloudgroupId>
                <artifactId>spring-cloud-dependenciesartifactId>
                <version>${spring-cloud.version}version>
                <type>pomtype>
                <scope>importscope>
            dependency>
              
            <dependency>
                <groupId>com.alibaba.cloudgroupId>
                <artifactId>spring-cloud-alibaba-dependenciesartifactId>
                <version>${spring-cloud-alibaba.version}version>
                <type>pomtype>
                <scope>importscope>
            dependency>
              
            <dependency>
                <groupId>org.projectlombokgroupId>
                <artifactId>lombokartifactId>
                <version>${lombok.version}version>
                <scope>providedscope>
            dependency>
 			  
            <dependency>
                <groupId>log4jgroupId>
                <artifactId>log4jartifactId>
                <version>1.2.17version>
            dependency>
              
            <dependency>
                <groupId>com.baomidougroupId>
                <artifactId>mybatis-plus-boot-starterartifactId>
                <version>3.5.3.1version>
            dependency>
              
            <dependency>
                <groupId>mysqlgroupId>
                <artifactId>mysql-connector-javaartifactId>
                <version>8.0.30version>
            dependency>
        dependencies>
    dependencyManagement>
project>

此时的项目结构

微服务的使用(一)_第3张图片

编写nacos-server项目中的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.0modelVersion>
   
    <parent>
        <groupId>org.examplegroupId>
        <artifactId>cloud-demoartifactId>
        <version>1.0-SNAPSHOTversion>
    parent>

    <artifactId>nacos-serverartifactId>
    <packaging>jarpackaging>

    <name>nacos-servername>
    <url>http://maven.apache.orgurl>

    <properties>
        <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
        <junit.version>4.13.2junit.version>

    properties>

    <dependencies>
        <dependency>
            <groupId>junitgroupId>
            <artifactId>junitartifactId>
            <version>${junit.version}version>
            <scope>testscope>
        dependency>
        <dependency>
            <groupId>com.alibaba.cloudgroupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discoveryartifactId>
        dependency>
        <dependency>
            <groupId>org.projectlombokgroupId>
            <artifactId>lombokartifactId>
        dependency>
    dependencies>
project>

此时我们能看到文件中出现的蓝色向上箭头,代表已经继承了父工程中的依赖容器。

微服务的使用(一)_第4张图片

你可能感兴趣的:(微服务,java,eureka)