springcloud pom.xml完整配置详解

 更新时间:2020年12月18日 08:49  点击:1821

1、父工程

<packaging>pom</packaging>

 <name>Maven</name>
 <!-- FIXME change it to the project's website -->
 <url>http://maven.apache.org/</url>
 <inceptionYear>2001</inceptionYear>

 <distributionManagement>
  <site>
   <id>website</id>
   <url>scp://webhost.company.com/www/website</url>
  </site>
 </distributionManagement>

 <properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <maven.compiler.source>12</maven.compiler.source>
  <maven.compiler.target>12</maven.compiler.target>
  <junit.version>4.12</junit.version>
  <lombok.version>1.18.10</lombok.version>
  <log4j.version>1.2.17</log4j.version>
  <mysql.version>8.0.18</mysql.version>
  <druid.version>1.1.16</druid.version>
  <mybatis.spring.boot.version>2.1.1</mybatis.spring.boot.version>
 </properties>

 <dependencyManagement>
  <dependencies>
   <!--父工程引入spring cloud alibaba 2.1.0.RELEASE-->
   <dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-alibaba-dependencies</artifactId>
    <version>2.1.0.RELEASE</version>
    <type>pom</type>
    <scope>import</scope>
   </dependency>

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

 </dependencyManagement>
 <!--maven插件-->
 <build>
  <plugins>
   <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
     <fork>true</fork>
     <addResources>true</addResources>
    </configuration><!---->
   </plugin>
  </plugins>
 </build>

2、子工程

 <dependencies>
  <dependency>
   <groupId>org.example</groupId>
   <artifactId>common-service</artifactId>
   <version>${project.version}</version>
  </dependency>
  <dependency>
   <groupId>com.aliyun.oss</groupId>
   <artifactId>aliyun-sdk-oss</artifactId>
   <version>2.8.2</version>
  </dependency>
  <dependency>

   <groupId>com.github.pagehelper</groupId>
   <artifactId>pagehelper-spring-boot-starter</artifactId>
   <version>1.2.10</version>

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

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<T> implements RedisSerializer<T> {
 public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
 private Class<T> clazz;
 public FastJsonRedisSerializer(Class<T> 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<Object, Object> redisTemplate(

   RedisConnectionFactory redisConnectionFactory) {

  RedisTemplate<Object, Object> 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配置内容请搜索猪先飞以前的文章或继续浏览下面的相关文章希望大家以后多多支持猪先飞!

[!--infotagslink--]

相关文章

  • 基于springcloud异步线程池、高并发请求feign的解决方案

    这篇文章主要介绍了基于springcloud异步线程池、高并发请求feign的解决方案,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-02-25
  • 完美解决SpringCloud-OpenFeign使用okhttp替换不生效问题

    这篇文章主要介绍了完美解决SpringCloud-OpenFeign使用okhttp替换不生效问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-02-25
  • 如何解决springcloud feign 首次调用100%失败的问题

    这篇文章主要介绍了如何解决springcloud feign 首次调用100%失败的问题,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2021-06-23
  • spring cloud gateway中如何读取请求参数

    这篇文章主要介绍了spring cloud gateway中如何读取请求参数的操作,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2021-07-15
  • 解决SpringCloud Feign传对象参数调用失败的问题

    这篇文章主要介绍了解决SpringCloud Feign传对象参数调用失败的问题,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2021-06-24
  • SpringCloud2020整合Nacos-Bootstrap配置不生效的解决

    这篇文章主要介绍了SpringCloud2020整合Nacos-Bootstrap配置不生效的解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-01-25
  • spring cloud gateway转发服务报错的解决

    这篇文章主要介绍了spring cloud gateway转发服务报错的解决,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2021-09-02
  • 解决springcloud-gateway限流遇到的问题

    这篇文章主要介绍了解决springcloud-gateway限流遇到的问题,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2021-07-16
  • SpringCloud @FeignClient参数的用法解析

    这篇文章主要介绍了SpringCloud @FeignClient参数的用法,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2021-10-21
  • 使用SpringCloudAlibaba整合Dubbo

    这篇文章主要介绍了使用SpringCloudAlibaba整合Dubbo,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2021-10-11
  • SpringCloud之@FeignClient()注解的使用方式

    这篇文章主要介绍了SpringCloud之@FeignClient()注解的使用方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2021-09-25
  • Spring Cloud中使用Feign,@RequestBody无法继承的解决方案

    这篇文章主要介绍了Spring Cloud中使用Feign,@RequestBody无法继承的解决方案,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2021-10-22
  • 使用maven开发springboot项目时pom.xml常用配置(推荐)

    这篇文章主要介绍了使用maven开发springboot项目时的pom.xml常用配置,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2021-01-08
  • 解决SpringCloud Config结合github无法读取配置的问题

    这篇文章主要介绍了解决SpringCloud Config结合github无法读取配置的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-02-25
  • 一篇文章教你如何在SpringCloud项目中使用OpenFeign

    这篇文章主要介绍了SpringCloud 使用Open feign 优化详解,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-08-16
  • Springcloud实现服务多版本控制的示例代码

    这篇文章主要介绍了Springcloud实现服务多版本控制的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-05-15
  • SpringCloud的JPA连接PostgreSql的教程

    这篇文章主要介绍了SpringCloud的JPA接入PostgreSql 教程,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2021-06-26
  • 5分钟搭建SpringCloud Eureka服务注册中心的实现

    这篇文章主要介绍了5分钟搭建SpringCloud Eureka服务注册中心的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-03-30
  • seata springcloud整合教程与遇到的坑

    seata 是alibaba 出的一款分布式事务管理器,他有侵入性小,实现简单等特点。这篇文章主要介绍了seata springcloud整合教程与遇到的坑,需要的朋友可以参考下...2021-07-07
  • springboot cloud使用eureka整合分布式事务组件Seata 的方法

    这篇文章主要介绍了springboot cloud使用eureka整合分布式事务组件Seata 的方法 ,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2021-05-02