springcloud pom.xml完整配置详解

1、父工程

pom

 Maven
 
 http://maven.apache.org/
 2001

 
  
   website
   scp://webhost.company.com/www/website
  
 

 
  UTF-8
  12
  12
  4.12
  1.18.10
  1.2.17
  8.0.18
  1.1.16
  2.1.1
 

 
  
   
   
    com.alibaba.cloud
    spring-cloud-alibaba-dependencies
    2.1.0.RELEASE
    pom
    import
   

   
    org.apache.maven.plugins
    maven-project-info-reports-plugin
    3.0.0
   
   
    
   org.springframework.cloud
   spring-cloud-starter-gateway
   
   
    org.springframework.boot
    spring-boot-dependencies
    2.2.2.RELEASE
    pom
    import
   
   
   
    org.springframework.cloud
    spring-cloud-dependencies
    Hoxton.SR1
    pom
    import
   
   
    com.alibaba.cloud
    spring-cloud-alibaba-dependencies
    2.1.0.RELEASE
    pom
    import
   
   
   
    mysql
    mysql-connector-java
    ${mysql.version}
    runtime
   
   
   
    com.alibaba
    druid
    ${druid.version}
   
   
    org.mybatis.spring.boot
    mybatis-spring-boot-starter
    ${mybatis.spring.boot.version}
   
   
   
    junit
    junit
    ${junit.version}
   
   
   
    log4j
    log4j
    ${log4j.version}
   
  

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

2、子工程

 
  
   org.example
   common-service
   ${project.version}
  
  
   com.aliyun.oss
   aliyun-sdk-oss
   2.8.2
  
  

   com.github.pagehelper
   pagehelper-spring-boot-starter
   1.2.10

  
  
   commons-lang
   commons-lang
   2.6
  
  
   io.springfox
   springfox-swagger2
   2.9.2
  
  
   io.github.openfeign
   feign-httpclient
  
  
   com.alibaba.csp
   sentinel-datasource-nacos
  
  
   io.springfox
   springfox-swagger-ui
   2.9.2
  
  
   org.springframework.cloud
   spring-cloud-starter-openfeign
  
  
  
   org.example
   common
   ${project.version}
  
  
   mysql
   mysql-connector-java
   8.0.18
  
  
   com.fasterxml.jackson.core
   jackson-core
   2.9.0
  
  
   com.fasterxml.jackson.core
   jackson-annotations
   2.9.0
  
  
   com.fasterxml.jackson.core
   jackson-databind
   2.9.0
  
  
   com.alibaba.cloud
   spring-cloud-starter-alibaba-nacos-config
  
  
   com.alibaba.cloud
   spring-cloud-starter-alibaba-nacos-discovery
  
  
   org.springframework.boot
   spring-boot-starter-amqp
  
  
   org.mybatis.spring.boot
   mybatis-spring-boot-starter
  
  
   org.springframework.boot
   spring-boot-starter-websocket
  
  
   com.alibaba
   fastjson
   1.2.41
  
  
    org.springframework.boot
    spring-boot-starter-data-redis
    
     
      redis.clients
      jedis
     
     
      io.lettuce
      lettuce-core
     
    
   
   
    redis.clients
    jedis
   
  
   org.springframework.boot
   spring-boot-starter-web
  
  
   org.projectlombok
   lombok
   true
  
 

3、swapper配置

package main.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
 @Bean
 public Docket createRestApi() {
  return new Docket(DocumentationType.SWAGGER_2)
    .apiInfo(apiInfo())
    .select()
    .apis(RequestHandlerSelectors.basePackage("main.controller"))
    .paths(PathSelectors.any())
    .build();

 }

 //配置在线文档的基本信息
 private ApiInfo apiInfo() {
  return new ApiInfoBuilder()
    .title("springboot利用swagger构建api文档")
    .description("简单优雅的restfun风格,https://me.csdn.net/blog/miachen520")
    .termsOfServiceUrl("https://me.csdn.net/blog/miachen520")
    .version("1.0")
    .build();

 }
}

4、跨域配置

package main.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class webConfig implements WebMvcConfigurer {

 @Override
 public void addCorsMappings(CorsRegistry registry) {
  // 设置允许跨域的路径
  registry.addMapping("/**")
    // 设置允许跨域请求的域名
    .allowedOrigins("*")
    // 是否允许证书
    .allowCredentials(true)
    .allowedMethods("*")
    .maxAge(3600);
 }
}

5、Redis序列化

serializer:

package main.config;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.parser.ParserConfig;
import com.alibaba.fastjson.serializer.SerializerFeature;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.SerializationException;
import java.nio.charset.Charset;
public class FastJsonRedisSerializer implements RedisSerializer {
 public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
 private Class clazz;
 public FastJsonRedisSerializer(Class clazz) {

  super();

  this.clazz = clazz;

 }

 @Override
 public byte[] serialize(T t) throws SerializationException {

  if (null == t) {

   return new byte[0];

  }

  return JSON.toJSONString(t, SerializerFeature.WriteClassName).getBytes(DEFAULT_CHARSET);

 }

 @Override
 public T deserialize(byte[] bytes) throws SerializationException {

  if (null == bytes || bytes.length <= 0) {

   return null;

  }

  String str = new String(bytes, DEFAULT_CHARSET);
  ParserConfig.getGlobalInstance().setAutoTypeSupport(true);
  return (T) JSON.parseObject(str, clazz);
 }
}

config:

package main.config;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration

@ConditionalOnClass(RedisOperations.class)

@EnableConfigurationProperties(RedisProperties.class)

public class redisConfig {
 @Bean

 @ConditionalOnMissingBean(name = "redisTemplate")

 public RedisTemplate redisTemplate(

   RedisConnectionFactory redisConnectionFactory) {

  RedisTemplate template = new RedisTemplate<>();

  //使用fastjson序列化

  FastJsonRedisSerializer fastJsonRedisSerializer = new FastJsonRedisSerializer(Object.class);

  // value值的序列化采用fastJsonRedisSerializer

  template.setValueSerializer(fastJsonRedisSerializer);

  template.setHashValueSerializer(fastJsonRedisSerializer);

  // key的序列化采用StringRedisSerializer

  template.setKeySerializer(new StringRedisSerializer());

  template.setHashKeySerializer(new StringRedisSerializer());

  template.setConnectionFactory(redisConnectionFactory);

  return template;

 }

 @Bean
 @ConditionalOnMissingBean(StringRedisTemplate.class)

 public StringRedisTemplate stringRedisTemplate(

   RedisConnectionFactory redisConnectionFactory) {

  StringRedisTemplate template = new StringRedisTemplate();

  template.setConnectionFactory(redisConnectionFactory);

  return template;

 }
}

到此这篇关于springcloud pom.xml完整配置的文章就介绍到这了,更多相关springcloud pom.xml配置内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

你可能感兴趣的:(springcloud pom.xml完整配置详解)