maven==docker搭建私有maven仓库,编写starter并发布到私有maven仓库,在项目中使用私有仓库中的starter


docker创建maven私有仓库

Linux使用docker搭建Maven私有仓库_Icoolkj的博客-CSDN博客_docker搭建maven仓库

docker run --name docker-nexus3 -p 8081:8081 -v /usr/local/nexus3/nexus-data:/nexus-data -d sonatype/nexus3

===============================================================

编写starter项目并推送到私有仓库:

  如何自定义一个springboot starter(超详细)_johnhum123的博客-CSDN博客_springboot自定义starter

  maven打包上传到私有仓库的步骤_茁壮成长的凌大大的博客-CSDN博客_maven发布到私有仓库

maven==docker搭建私有maven仓库,编写starter并发布到私有maven仓库,在项目中使用私有仓库中的starter_第1张图片

 



    4.0.0

    org.example
    test-spring-boot-starter
    0.3

    
        spring-boot-starter-parent
        org.springframework.boot
        2.5.2
    


    
        8
        8
    

    
        
            org.springframework.boot
            spring-boot-configuration-processor
            true
        
        
            org.springframework.boot
            spring-boot-autoconfigure
        
    

    
    
        
            maven-releases
            Nexus Release Repository
            http://162.14.114.186:8081/repository/maven-releases/
        
        
            maven-snapshots
            Nexus Snapshot Repository
            http://162.14.114.186:8081/repository/maven-snapshots/
        
    

    
        
            
            
                org.apache.maven.plugins
                maven-source-plugin
                3.0.1
                
                    true
                
                
                    
                        compile
                        
                            jar
                        
                    
                
            
        
    



package org.example.test.spring.boot.starter;

import java.util.List;

/**
 * @author Johnhum on 2021/7/18
 */
public interface ISplitService {
    List split(String value);
}

 

package org.example.test.spring.boot.starter;


import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
@ConditionalOnClass(value = {ISplitService.class, SplitServiceImpl.class})
public class SplitAutoConfigure {
    @Bean
    @ConditionalOnMissingBean
    ISplitService startService() {
        return new SplitServiceImpl();
    }
}
package org.example.test.spring.boot.starter;


import org.springframework.util.StringUtils;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author Johnhum on 2021/7/18
 */
public class SplitServiceImpl implements ISplitService {
    @SuppressWarnings("all")
    @Override
    public List split(String value) {
        return Stream.of(StringUtils.split(value, ",")).collect(Collectors.toList());
    }
}

\test-spring-boot-starter\test-spring-boot-starter\src\main\resources\META-INF\spring.factories

org.springframework.boot.autoconfigure.EnableAutoConfiguration=org.example.test.spring.boot.starter.SplitAutoConfigure

 mvn deploy

maven==docker搭建私有maven仓库,编写starter并发布到私有maven仓库,在项目中使用私有仓库中的starter_第2张图片

 成功上传了

maven==docker搭建私有maven仓库,编写starter并发布到私有maven仓库,在项目中使用私有仓库中的starter_第3张图片

 

 ======================================

清空本地maven仓库的所有依赖包,然后新建一个maven项目,引入上面新建的starter



    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.5.2
         
    
    com.example
    test-use-starter2
    0.0.1-SNAPSHOT
    test-use-starter2
    test-use-starter2
    
        1.8
    
    
        
            org.springframework.boot
            spring-boot-starter-web
        

        
            org.projectlombok
            lombok
            true
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        

        
            com.alibaba
            fastjson
            2.0.3
        
        
            org.example
            test-spring-boot-starter
            0.3
        
    

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


 

package com.example.testusestarter2;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class TestUseStarter2Application {

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

}
package com.example.testusestarter2;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.example.test.spring.boot.starter.ISplitService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
@Slf4j
class TestUseStarter2ApplicationTests {

    @Test
    void contextLoads() {
    }

    @Autowired
    private ISplitService splitServiceImpl;

    @Test
    public void splitTest() {
        log.info("split context: {}", JSON.toJSONString(splitServiceImpl.split("8888,6666666666")));
    }
}

 

maven==docker搭建私有maven仓库,编写starter并发布到私有maven仓库,在项目中使用私有仓库中的starter_第4张图片

 maven==docker搭建私有maven仓库,编写starter并发布到私有maven仓库,在项目中使用私有仓库中的starter_第5张图片

 

===============================================================

原理,springboot注解@Configuration

@Configuration就是个bean工厂,工厂类中的方法就是生成bean的方法

见spring refresh和spring bean源码分析 

你可能感兴趣的:(maven,maven,java,spring)