Commit 31ac204d authored by 张永's avatar 张永

升个版本

parent 1fac5124
Pipeline #163 canceled with stages
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.egolm</groupId> <groupId>com.egolm</groupId>
<artifactId>oms</artifactId> <artifactId>oms</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<description>订单管理</description> <description>订单管理</description>
<properties> <properties>
<start-class>com.egolm.oms.OmsApplication</start-class> <start-class>com.egolm.oms.OmsApplication</start-class>
</properties> </properties>
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version> <version>2.1.0.RELEASE</version>
</parent> </parent>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId> <artifactId>spring-boot-devtools</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
<groupId>mysql</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>mysql-connector-java</artifactId> <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency> <!-- https://blog.csdn.net/weixin_39723544/article/details/80743074 整合 -->
<dependency> <!-- 1.5的版本默认采用的连接池技术是jedis 2.0以上版本默认连接池是lettuce, 在这里采用jedis,所以需要排除lettuce的jar -->
<groupId>com.microsoft.sqlserver</groupId> <exclusions>
<artifactId>sqljdbc4</artifactId> <exclusion>
<version>4.0</version> <groupId>redis.clients</groupId>
</dependency> <artifactId>jedis</artifactId>
<dependency> </exclusion>
<groupId>com.alibaba</groupId> <exclusion>
<artifactId>fastjson</artifactId> <groupId>io.lettuce</groupId>
<version>1.2.38</version> <artifactId>lettuce-core</artifactId>
</dependency> </exclusion>
<dependency> </exclusions>
<groupId>com.egolm</groupId> </dependency>
<artifactId>common</artifactId> <!-- 添加jedis客户端 -->
<version>0.0.1-RELEASE</version> <dependency>
</dependency> <groupId>redis.clients</groupId>
<dependency> <artifactId>jedis</artifactId>
<groupId>com.alibaba</groupId> </dependency>
<artifactId>druid</artifactId> <dependency>
<version>1.1.6</version> <groupId>mysql</groupId>
</dependency> <artifactId>mysql-connector-java</artifactId>
<dependency> </dependency>
<groupId>io.springfox</groupId> <dependency>
<artifactId>springfox-swagger2</artifactId> <groupId>com.microsoft.sqlserver</groupId>
<version>2.6.1</version> <artifactId>sqljdbc4</artifactId>
</dependency> <version>4.0</version>
<dependency> </dependency>
<groupId>io.springfox</groupId> <dependency>
<artifactId>springfox-swagger-ui</artifactId> <groupId>com.alibaba</groupId>
<version>2.6.1</version> <artifactId>fastjson</artifactId>
</dependency> <version>1.2.38</version>
<dependency> </dependency>
<groupId>net.sf.ehcache</groupId> <dependency>
<artifactId>ehcache</artifactId> <groupId>com.egolm</groupId>
</dependency> <artifactId>common</artifactId>
</dependencies> <version>0.0.1-RELEASE</version>
<build> </dependency>
<plugins> <dependency>
<plugin> <groupId>com.alibaba</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>druid</artifactId>
<configuration> <version>1.1.6</version>
<source>1.8</source> </dependency>
<target>1.8</target> <dependency>
</configuration> <groupId>io.springfox</groupId>
</plugin> <artifactId>springfox-swagger2</artifactId>
<plugin> <version>2.6.1</version>
<groupId>org.springframework.boot</groupId> </dependency>
<artifactId>spring-boot-maven-plugin</artifactId> <dependency>
<configuration> <groupId>io.springfox</groupId>
<mainClass>${start-class}</mainClass> <artifactId>springfox-swagger-ui</artifactId>
<layout>ZIP</layout> <version>2.6.1</version>
</configuration> </dependency>
<executions> <dependency>
<execution> <groupId>net.sf.ehcache</groupId>
<goals> <artifactId>ehcache</artifactId>
<goal>repackage</goal> </dependency>
</goals> </dependencies>
</execution> <build>
</executions> <plugins>
</plugin> <plugin>
</plugins> <artifactId>maven-compiler-plugin</artifactId>
</build> <configuration>
<source>1.8</source>
<repositories> <target>1.8</target>
<repository> </configuration>
<id>my</id> </plugin>
<name>my</name> <plugin>
<url>http://git.egolm.com:9003/nexus/content/groups/public/</url> <groupId>org.springframework.boot</groupId>
</repository> <artifactId>spring-boot-maven-plugin</artifactId>
<repository> <configuration>
<id>repo1</id> <mainClass>${start-class}</mainClass>
<name>repo1</name> <layout>ZIP</layout>
<url>http://repo1.maven.org/maven2/</url> </configuration>
</repository> <executions>
<repository> <execution>
<id>mvnrepository</id> <goals>
<name>mvnrepository</name> <goal>repackage</goal>
<url>http://mvnrepository.com/</url> </goals>
</repository> </execution>
</repositories> </executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>my</id>
<name>my</name>
<url>http://git.egolm.com:9003/nexus/content/groups/public/</url>
</repository>
<repository>
<id>repo1</id>
<name>repo1</name>
<url>http://repo1.maven.org/maven2/</url>
</repository>
<repository>
<id>mvnrepository</id>
<name>mvnrepository</name>
<url>http://mvnrepository.com/</url>
</repository>
</repositories>
</project> </project>
\ No newline at end of file
package com.egolm.oms.config; package com.egolm.oms.config;
import javax.sql.DataSource; import javax.sql.DataSource;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.PlatformTransactionManager;
import com.alibaba.druid.pool.DruidDataSource; import com.alibaba.druid.pool.DruidDataSource;
import com.egolm.common.jdbc.JdbcTemplate; import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.common.jdbc.dialect.MySqlDialect; import com.egolm.common.jdbc.dialect.MySqlDialect;
@Configuration @Configuration
public class DataSourceConfig { public class DataSourceConfig {
@Bean @Bean
@Primary @Primary
@ConfigurationProperties(prefix = "spring.datasource") @ConfigurationProperties(prefix = "spring.datasource")
public DataSource getDataSource() { public DataSource getDataSource() {
return DataSourceBuilder.create().type(DruidDataSource.class).build(); return DataSourceBuilder.create().type(DruidDataSource.class).build();
} }
@Bean @Bean
@Primary @Primary
public PlatformTransactionManager getTransactionManager(DataSource dataSource) { public PlatformTransactionManager getTransactionManager(DataSource dataSource) {
return new DataSourceTransactionManager(dataSource); return new DataSourceTransactionManager(dataSource);
} }
@Bean @Bean
@Primary @Primary
public JdbcTemplate getJdbcTemplate(DataSource dataSource) { public JdbcTemplate getJdbcTemplate(DataSource dataSource) {
JdbcTemplate jdbcTemplate = new JdbcTemplate(); JdbcTemplate jdbcTemplate = new JdbcTemplate();
jdbcTemplate.setDataSource(dataSource); jdbcTemplate.setDataSource(dataSource);
jdbcTemplate.setDialect(new MySqlDialect()); jdbcTemplate.setDialect(new MySqlDialect());
jdbcTemplate.setSql_level(3); jdbcTemplate.setSql_level(3);
return jdbcTemplate; return jdbcTemplate;
} }
} }
\ No newline at end of file
package com.egolm.oms.config;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.interceptor.CacheErrorHandler;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
@Configuration
// 必须加,使配置生效
@EnableCaching
public class RedisConfiguration extends CachingConfigurerSupport {
/**
* Logger
*/
private static final Logger lg = LoggerFactory.getLogger(RedisConfiguration.class);
@Autowired
private JedisConnectionFactory jedisConnectionFactory;
@Bean
@Override
public KeyGenerator keyGenerator() {
// 设置自动key的生成规则,配置spring boot的注解,进行方法级别的缓存
// 使用:进行分割,可以很多显示出层级关系
// 这里其实就是new了一个KeyGenerator对象,只是这是lambda表达式的写法,我感觉很好用,大家感兴趣可以去了解下
return (target, method, params) -> {
StringBuilder sb = new StringBuilder();
sb.append(target.getClass().getName());
sb.append(":");
sb.append(method.getName());
for (Object obj : params) {
sb.append(":" + String.valueOf(obj));
}
String rsToUse = String.valueOf(sb);
lg.info("自动生成Redis Key -> [{}]", rsToUse);
return rsToUse;
};
}
@Bean
@Override
public CacheManager cacheManager() {
// 初始化缓存管理器,在这里我们可以缓存的整体过期时间什么的,我这里默认没有配置
lg.info("初始化 -> [{}]", "CacheManager RedisCacheManager Start");
RedisCacheManager.RedisCacheManagerBuilder builder = RedisCacheManager
.RedisCacheManagerBuilder
.fromConnectionFactory(jedisConnectionFactory);
return builder.build();
}
@Bean
public RedisTemplate<String, Object> redisTemplate(JedisConnectionFactory jedisConnectionFactory ) {
//设置序列化
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jackson2JsonRedisSerializer.setObjectMapper(om);
// 配置redisTemplate
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<String, Object>();
redisTemplate.setConnectionFactory(jedisConnectionFactory);
RedisSerializer stringSerializer = new StringRedisSerializer();
redisTemplate.setKeySerializer(stringSerializer); // key序列化
redisTemplate.setValueSerializer(jackson2JsonRedisSerializer); // value序列化
redisTemplate.setHashKeySerializer(stringSerializer); // Hash key序列化
redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer); // Hash value序列化
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
@Override
@Bean
public CacheErrorHandler errorHandler() {
// 异常处理,当Redis发生异常时,打印日志,但是程序正常走
lg.info("初始化 -> [{}]", "Redis CacheErrorHandler");
CacheErrorHandler cacheErrorHandler = new CacheErrorHandler() {
@Override
public void handleCacheGetError(RuntimeException e, Cache cache, Object key) {
lg.error("Redis occur handleCacheGetError:key -> [{}]", key, e);
}
@Override
public void handleCachePutError(RuntimeException e, Cache cache, Object key, Object value) {
lg.error("Redis occur handleCachePutError:key -> [{}];value -> [{}]", key, value, e);
}
@Override
public void handleCacheEvictError(RuntimeException e, Cache cache, Object key) {
lg.error("Redis occur handleCacheEvictError:key -> [{}]", key, e);
}
@Override
public void handleCacheClearError(RuntimeException e, Cache cache) {
lg.error("Redis occur handleCacheClearError:", e);
}
};
return cacheErrorHandler;
}
/**
* 此内部类就是把yml的配置数据,进行读取,创建JedisConnectionFactory和JedisPool,以供外部类初始化缓存管理器使用
* 不了解的同学可以去看@ConfigurationProperties和@Value的作用
*
*/
@ConfigurationProperties
class DataJedisProperties{
@Value("${spring.redis.host}")
private String host;
@Value("${spring.redis.password}")
private String password;
@Value("${spring.redis.port}")
private int port;
@Value("${spring.redis.timeout}")
private int timeout;
@Value("${spring.redis.jedis.max-idle}")
private int maxIdle;
@Value("${spring.redis.jedis.max-wait}")
private long maxWaitMillis;
@SuppressWarnings("deprecation")
@Bean
JedisConnectionFactory jedisConnectionFactory() {
lg.info("Create JedisConnectionFactory successful");
JedisConnectionFactory factory = new JedisConnectionFactory();
factory.setHostName(host);
factory.setPort(port);
factory.setTimeout(timeout);
factory.setPassword(password);
return factory;
}
@Bean
public JedisPool redisPoolFactory() {
lg.info("JedisPool init successful,host -> [{}];port -> [{}]", host, port);
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
jedisPoolConfig.setMaxIdle(maxIdle);
jedisPoolConfig.setMaxWaitMillis(maxWaitMillis);
JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout, password);
return jedisPool;
}
}
}
\ No newline at end of file
server.tomcat.max-threads=1000 server.tomcat.max-threads=1000
server.tomcat.min-spare-threads=30 server.tomcat.min-spare-threads=30
server.port=30003 server.port=30003
server.context-path=/oms server.context-path=/oms
server.session.timeout=90000 server.session.timeout=90000
server.tomcat.uri-encoding=utf-8 server.tomcat.uri-encoding=utf-8
spring.http.multipart.maxFileSize=5MB spring.http.multipart.maxFileSize=5MB
spring.http.multipart.maxRequestSize=5MB spring.http.multipart.maxRequestSize=5MB
spring.http.encoding.force=true spring.http.encoding.force=true
spring.http.encoding.enabled=true spring.http.encoding.enabled=true
spring.http.encoding.charset=utf-8 spring.http.encoding.charset=utf-8
spring.datasource.username=ERP spring.datasource.username=ERP
spring.datasource.password=qiyang@2013 spring.datasource.password=qiyang@2013
spring.datasource.url=jdbc:sqlserver://10.10.0.22:1433;instanceName=SQLSERVER;DatabaseName=EGOLMDEV spring.datasource.url=jdbc:sqlserver://10.10.0.22:1433;instanceName=SQLSERVER;DatabaseName=EGOLMDEV
spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.testWhileIdle=true spring.datasource.testWhileIdle=true
spring.datasource.validationQueryTimeout=5 spring.datasource.validationQueryTimeout=5
spring.datasource.validationQuery=SELECT 1 spring.datasource.validationQuery=SELECT 1
spring.datasource.timeBetweenEvictionRunsMillis=3600000 spring.datasource.timeBetweenEvictionRunsMillis=3600000
\ No newline at end of file
######redis
spring.redis.host=10.10.0.15
spring.redis.port=16379
spring.redis.database=10
spring.redis.password=
spring.redis.timeout=3000
spring.redis.jedis.max-active=5
spring.redis.jedis.max-idle=5
spring.redis.jedis.max-wait=5
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment