自定义cache-spring-boot-starter到私服

1、配置maven仓库配置文件



    
	D:\JAVA\Maven\Repository
	
	 
    
        
            aliuxy-releases
            admin
            admin123
        
        
            aliuxy-snapshots
              admin
            admin123
        
    
	
	  
	
        
            nexus
			*
            http://10.10.0.20:8081/repository/aliuxy-public/
        
    
	
	
	  
    
        
            aliuxy
            
				  
					aliuxy-public
					aliuxy-public
					http://10.10.0.20:8081/repository/aliuxy-public/  
					  
					  true
					  
					  
					  true  
					  
				   
            
        
    
    
        aliuxy
    


2.新建maven项目
目录结构:
自定义cache-spring-boot-starter到私服_第1张图片

  • resource文件夹下建META-INF文件夹,然后META-INF下建spring.factories文件,SpringBoot在启动时,默认加载并配置classpath下META-INF/spring.factories中的指定的配置类,简单来说,我们只需指定好配置类的类路径,剩下的交给SpringBoot来加载并自动装配。文件内容:
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.aliuxy.starter.CacheAutoConfiguration
  • 配置入口,将所需的所有Bean都配置到spring中:
package com.aliuxy.starter;

import com.aliuxy.starter.configure.RedisAutoConfigure;
import com.aliuxy.starter.redisson.configure.RedissonAutoConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * 自动装配入口
 *@author liuxingying
 *@since 2021/8/7
 */
@EnableCaching
@Configuration
@Import({RedisAutoConfigure.class, RedissonAutoConfiguration.class})
public class CacheAutoConfiguration {

    public CacheAutoConfiguration() {
    }

    @Bean
    public KeyGenerator keyGenerator() {
        return (target, method, objects) -> {
            StringBuilder sb = new StringBuilder();
            sb.append(target.getClass().getName());
            sb.append(":");
            sb.append(method.getName());
            Object[] var4 = objects;
            int var5 = objects.length;

            for(int var6 = 0; var6 < var5; ++var6) {
                Object obj = var4[var6];
                if (obj != null) {
                    sb.append(":");
                    sb.append(obj.toString());
                }
            }

            return sb.toString();
        };
    }
}

ps:入口注解有很多,将按需配置,比如类似yml配置来激活是否生效Configuration:

/**
 * 配置类,交给IOC容器
 * @EnableConfigurationProperties:告诉SpringBoot,让使用@ConfigurationProperties 注解的类生效。
 * @ConditionalOnProperty:
 * 注解控制 @Configuration是否生效。
 * 简单来说也就是我们可以通过在yml配置文件中控制 
 * @Configuration 注解的配置类是否生效
 */
@Configuration
@EnableConfigurationProperties(XfProperties.class)
@ConditionalOnProperty(prefix = "xf",value = "enabled", matchIfMissing = true)
public class XfConfig {
        @Autowired
        private XfProperties xfProperties;
        @Bean
        public XfService xfService(){
            return  new XfService(xfProperties.getMsg(),xfProperties.getToWho());
        }
}

3.配置文件pom.xml



    4.0.0

    com.aliuxy
    cache-spring-boot-starter
    1.0.0-SNAPSHOT

    cache-spring-boot-starter

    cache-spring-boot-starter upload nexus

    
        1.8
    


    
        
        
            org.springframework.boot
            spring-boot-autoconfigure
        

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

        
            org.springframework.boot
            spring-boot-starter-aop
        

        
            org.projectlombok
            lombok
            1.18.12
        

        
        
            org.springframework.boot
            spring-boot-starter-data-redis
        

        
            org.springframework.boot
            spring-boot-starter-cache
        

        
        
            org.redisson
            redisson
            3.10.5
        

        
            com.fasterxml.jackson.datatype
            jackson-datatype-jsr310
        

        
            com.alibaba
            fastjson
            1.2.76
        

        
            org.apache.commons
            commons-lang3
        

        
            com.google.guava
            guava
            27.0.1-jre
            compile
        
    
    
        
        
            
                org.springframework.boot
                spring-boot-dependencies
                2.1.4.RELEASE
                pom
                import
            
        
    

    
        
            aliuxy-releases
            http://10.10.0.20:8081/repository/aliuxy-releases/
        
        
            aliuxy-snapshots
            http://10.10.0.20:8081/repository/aliuxy-snapshots/
        
    
  
    
        
            
                src/main/resources
                
                    **/*
                
                true
            
        
        
            
                
                    org.apache.maven.plugins
                    maven-compiler-plugin
                    3.1
                    
                        1.8
                        1.8
                        UTF-8
                    
                
                
                
                    org.apache.maven.plugins
                    maven-resources-plugin
                    2.6
                    
                        UTF-8
                        
                        
                            pem
                            pfx
                            p12
                            key
                        
                    
                
                
                
                    org.apache.maven.plugins
                    maven-javadoc-plugin
                    3.3.0
                    
                        UTF-8
                        UTF-8
                        UTF-8
                    
                    
                        
                            attach-javadocs
                            
                                jar
                            
                            
                                -Xdoclint:none
                            
                        
                    
                
                
                
                    org.apache.maven.plugins
                    maven-source-plugin
                    3.2.1
                    
                        
                            attach-sources
                            
                                jar
                            
                        
                    
                
                
                
                    org.codehaus.mojo
                    versions-maven-plugin
                    2.8.1
                    
                        false
                    
                
                
                    org.apache.maven.plugins
                    maven-gpg-plugin
                    1.6
                
            
        

        
            
            
                org.apache.maven.plugins
                maven-compiler-plugin
            
            
            
                org.apache.maven.plugins
                maven-resources-plugin
            
            
            
                org.apache.maven.plugins
                maven-javadoc-plugin
            
            
            
                org.apache.maven.plugins
                maven-source-plugin
            
            
            
                org.codehaus.mojo
                versions-maven-plugin
                
                    false
                
            
        
    




  • 所需内容完善后,就可以deploy打包上传到本地仓库和远程私服nexus上了,其他服务需要就可以直接引用

你可能感兴趣的:(maven)