如何使用SpringCloudAliBaba技术栈搭建微服务环境

首先创建一个父模块(怎么创建应该就不用多说了吧,重点是依赖这些东西,我这里是大致拿出我其中的一个项目做例子)


    4.0.0

    com.gq
    Shopping
    1.0-SNAPSHOT
    pom

    
    

        shopping_common

        shopping_goods_service

        shopping_manager_api

        shopping_admin_service

        shopping_file_service

        shopping_category_service

        shopping_category_customer_api

        shopping_search_service

        shopping_search_customer_api

        shopping_message_service

        shopping_user_service

        shopping_user_customer_api
    

    
        17
        3.2.4
        UTF-8
        UTF-8
        3.0.2
        2022.0.0
        2022.0.0.0
        1.18.28
        3.5.4
    

    
    
        
            
            
                org.springframework.cloud
                spring-cloud-dependencies
                ${spring-cloud.version}
                pom
                import
            

            
            
                com.alibaba.cloud
                spring-cloud-alibaba-dependencies
                ${spring-cloud-alibaba.version}
                pom
                import
            

            
            
                org.springframework.boot
                spring-boot-dependencies
                ${spring-boot.version}
                pom
                import
            

            
            
                org.apache.dubbo
                dubbo-bom
                ${dubbo.version}
                pom
                import
            

            
            
                org.projectlombok
                lombok
                ${lombok.version}
            

            
            
                com.baomidou
                mybatis-plus-boot-starter
                ${mybatis-plus.version}
            
        
    

    
    
        
        
            org.springframework.cloud
            spring-cloud-starter-bootstrap
        
    

    
    
        
            
                org.apache.maven.plugins
                maven-compiler-plugin
                
                    ${java.version}
                    ${java.version}
                    ${project.build.sourceEncoding}
                
            
        
    

    
    
        
            public
            aliyun nexus
            https://maven.aliyun.com/repository/public
            
                true
            
        
    

    
    
        
            public
            aliyun nexus
            https://maven.aliyun.com/repository/public
            
                true
            
            
                false
            
        
    

列举其中一个有数据源的子服务模块:



    4.0.0
    
        com.gq
        Shopping
        1.0-SNAPSHOT
    
    com.gq
    shopping_admin_service
    0.0.1-SNAPSHOT
    shopping_admin_service
    shopping_admin_service
    
    
        
    
    
        
    
    
        
        
        
        
    
    
        17
    
    
        
        
            com.baomidou
            mybatis-plus-boot-starter
        
        
        
            mysql
            mysql-connector-java
            runtime
        
        
            com.gq
            shopping_common
            0.0.1-SNAPSHOT
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        
        
        
            org.apache.dubbo
            dubbo-spring-boot-starter
        
        
            org.apache.dubbo
            dubbo-registry-nacos
        
        
        
            com.alibaba.cloud
            spring-cloud-starter-alibaba-nacos-config
        
        
            com.alibaba.cloud
            spring-cloud-starter-alibaba-nacos-discovery
        
    


    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    


(1)启动类

package com.gq.shopping_admin_service;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@MapperScan("com.gq.shopping_admin_service.mapper")
@EnableDiscoveryClient
@EnableDubbo
@RefreshScope
public class ShoppingAdminServiceApplication {

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

    // 分页插件
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }
}

基本上都是这样创建的!

你可能感兴趣的:(分布式架构,环境搭建,Java项目实用知识,微服务,架构,java)