springcloud pom.xml完整配置详解

网友投稿 260 2023-02-13

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

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;

}

}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:短信验证码 聚合数据(短信验证码 聚合数据什么意思)
下一篇:基于SSM实现学生管理系统
相关文章

 发表评论

暂时没有评论,来抢沙发吧~