Skip to content

Commit

Permalink
Merge pull request #13 from buession/development
Browse files Browse the repository at this point in the history
Release 2.3.2
  • Loading branch information
eduosi authored Dec 27, 2023
2 parents 91dd183 + a8f736d commit 656e651
Show file tree
Hide file tree
Showing 43 changed files with 420 additions and 503 deletions.
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@
===========================


## [2.3.2](https://github.com/buession/buession-springboot/releases/tag/v2.3.2) (2023-12-27)

### 🔨依赖升级

- [依赖库版本升级和安全漏洞修复](https://github.com/buession/buession-parent/releases/tag/v2.3.2)


### ⭐ 新特性

- **buession-springboot-httpclient:** OKHTTP client 增加可设置 maxRequests


### 🐞 Bug 修复

- **buession-springboot-mybatis:** 修复 Environment 获取 spring.mybatis.annotation-class 转换成 Class 异常 BUG
- **buession-springboot-mybatis:** 修复无法获取 spring.mybatis.scanner.base-package 的 BUG


### ⏪ 优化

- **buession-springboot-cache:** RedisTemplate 初始化时不手动调用 afterPropertiesSet 方法
- **buession-springboot-cache:** 优化 AbstractDataSourceFactoryBean 多次调用 afterPropertiesSet 时,重复初始化 dataSource
- **buession-springboot-boot:** 代码质量优化


---


## [2.3.1](https://github.com/buession/buession-springboot/releases/tag/v2.3.1) (2023-11-17)

### 🔨依赖升级
Expand Down
2 changes: 1 addition & 1 deletion buession-springboot-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>com.buession.springboot</groupId>
<artifactId>buession-springboot-parent</artifactId>
<relativePath>../buession-springboot-parent</relativePath>
<version>2.3.1</version>
<version>2.3.2</version>
</parent>
<artifactId>buession-springboot-boot</artifactId>
<url>https://springboot.buession.com/</url>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and limitations under the License.
*
* =========================================================================================================
*
* This software consists of voluntary contributions made by many individuals on behalf of the
* Apache Software Foundation. For more information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* +-------------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng <[email protected]> |
* | Copyright @ 2013-2023 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.springboot.boot;

import com.buession.core.utils.VersionUtils;

/**
* @author Yong.Teng
* @since 2.3.2
*/
public class BuessionBootVersion {

private BuessionBootVersion() {

}

public static String getVersion() {
return VersionUtils.determineClassVersion(BuessionBootVersion.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
*/
package com.buession.springboot.boot.banner;

import com.buession.core.Framework;
import com.buession.core.BuessionFrameworkVersion;
import com.buession.core.utils.JceUtils;
import com.buession.core.utils.StringUtils;
import com.buession.core.utils.VersionUtils;
import com.buession.springboot.boot.BuessionBootVersion;
import com.buession.springboot.boot.utils.FileUtils;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringBootVersion;
Expand Down Expand Up @@ -59,7 +60,7 @@ public abstract class AbstractBanner implements Banner {
private final static String BANNER_SKIP_PROPERTY_NAME = "BANNER_SKIP";

@Override
public void printBanner(Environment environment, Class<?> sourceClass, PrintStream out){
public void printBanner(Environment environment, Class<?> sourceClass, PrintStream out) {
String additional = collectEnvironmentInfo(environment, sourceClass);

try{
Expand All @@ -76,7 +77,7 @@ public void printBanner(Environment environment, Class<?> sourceClass, PrintStre
}
}

protected String getTitle(){
protected String getTitle() {
return '\n'
+ "______ _ \n" +
"| ___ \\ (_) \n" +
Expand All @@ -87,15 +88,15 @@ protected String getTitle(){
" \n";
}

protected String getVersion(){
protected String getVersion() {
return getVersion(getClass());
}

protected <T> String getVersion(Class<T> clazz){
protected <T> String getVersion(Class<T> clazz) {
return clazz == null ? null : VersionUtils.determineClassVersion(clazz);
}

private String collectEnvironmentInfo(final Environment environment, final Class<?> sourceClass){
private String collectEnvironmentInfo(final Environment environment, final Class<?> sourceClass) {
Properties properties = System.getProperties();
Throwable throwable = null;

Expand All @@ -107,33 +108,7 @@ private String collectEnvironmentInfo(final Environment environment, final Class

try{
if(properties.containsKey(BANNER_SKIP_PROPERTY_NAME) == false){
formatter.format("Buession Framework Version: %s%n", Framework.VERSION);
formatter.format("Buession Spring Boot Version: %s%n", getVersion(AbstractBanner.class));
formatter.format("%s%n", LINE_SEPARATOR);

formatter.format("Spring Framework Version: %s%n", SpringVersion.getVersion());
formatter.format("Spring Boot Framework Version: %s%n", SpringBootVersion.getVersion());
formatter.format("%s%n", LINE_SEPARATOR);

formatter.format("OS Architecture: %s%n", properties.get("os.arch"));
formatter.format("OS Name: %s%n", properties.get("os.name"));
formatter.format("OS Version: %s%n", properties.get("os.version"));
formatter.format("System Date Time: %s%n", LocalDateTime.now());
formatter.format("System Temp Directory: %s%n", System.getProperty("java.io.tmpdir"));
formatter.format("User Home: %s%n", System.getProperty("user.home"));
formatter.format("%s%n", LINE_SEPARATOR);

Runtime runtime = Runtime.getRuntime();

formatter.format("Java Home: %s%n", properties.get("java.home"));
formatter.format("Java Vendor: %s%n", properties.get("java.vendor"));
formatter.format("Java Version: %s%n", properties.get("java.version"));
formatter.format("JVM Total Memory: %s%n", FileUtils.byteCountToDisplaySize(runtime.totalMemory()));
formatter.format("JVM Maximum Memory: %s%n", FileUtils.byteCountToDisplaySize(runtime.maxMemory()));
formatter.format("JVM Free Memory: %s%n", FileUtils.byteCountToDisplaySize(runtime.freeMemory()));
formatter.format("JCE Installed: %s%n", JceUtils.isInstalled() ? "Yes" : "No");
formatter.format("%s%n", LINE_SEPARATOR);

collectEnvironmentInfo(properties, formatter);
injectEnvironmentInfoIntoBanner(formatter, environment, sourceClass);
}

Expand All @@ -146,11 +121,40 @@ private String collectEnvironmentInfo(final Environment environment, final Class
}
}

private void collectEnvironmentInfo(final Properties properties, final Formatter formatter) {
formatter.format("Buession Framework Version: %s%n", BuessionFrameworkVersion.getVersion());
formatter.format("Buession Spring Boot Version: %s%n", BuessionBootVersion.getVersion());
formatter.format("%s%n", LINE_SEPARATOR);

formatter.format("Spring Framework Version: %s%n", SpringVersion.getVersion());
formatter.format("Spring Boot Framework Version: %s%n", SpringBootVersion.getVersion());
formatter.format("%s%n", LINE_SEPARATOR);

formatter.format("OS Architecture: %s%n", properties.get("os.arch"));
formatter.format("OS Name: %s%n", properties.get("os.name"));
formatter.format("OS Version: %s%n", properties.get("os.version"));
formatter.format("System Date Time: %s%n", LocalDateTime.now());
formatter.format("System Temp Directory: %s%n", System.getProperty("java.io.tmpdir"));
formatter.format("User Home: %s%n", System.getProperty("user.home"));
formatter.format("%s%n", LINE_SEPARATOR);

Runtime runtime = Runtime.getRuntime();

formatter.format("Java Home: %s%n", properties.get("java.home"));
formatter.format("Java Vendor: %s%n", properties.get("java.vendor"));
formatter.format("Java Version: %s%n", properties.get("java.version"));
formatter.format("JVM Total Memory: %s%n", FileUtils.byteCountToDisplaySize(runtime.totalMemory()));
formatter.format("JVM Maximum Memory: %s%n", FileUtils.byteCountToDisplaySize(runtime.maxMemory()));
formatter.format("JVM Free Memory: %s%n", FileUtils.byteCountToDisplaySize(runtime.freeMemory()));
formatter.format("JCE Installed: %s%n", JceUtils.isInstalled() ? "Yes" : "No");
formatter.format("%s%n", LINE_SEPARATOR);
}

protected void injectEnvironmentInfoIntoBanner(final Formatter formatter, final Environment environment,
final Class<?> sourceClass){
final Class<?> sourceClass) {
}

private static void closeFormatter(Formatter formatter, Throwable throwable){
private static void closeFormatter(Formatter formatter, Throwable throwable) {
try{
formatter.close();
}catch(Throwable t){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* +------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng <[email protected]> |
* | Copyright @ 2013-2017 Buession.com Inc. |
* | Copyright @ 2013-2023 Buession.com Inc. |
* +------------------------------------------------------------------------------------------------+
*/
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional information regarding
* copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*
* =================================================================================================
*
* This software consists of voluntary contributions made by many individuals on behalf of the
* Apache Software Foundation. For more information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* +------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng <[email protected]> |
* | Copyright @ 2013-2023 Buession.com Inc. |
* +------------------------------------------------------------------------------------------------+
*/
/**
* @author Yong.Teng
*/
package com.buession.springboot.boot;
2 changes: 1 addition & 1 deletion buession-springboot-cache/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>com.buession.springboot</groupId>
<artifactId>buession-springboot-parent</artifactId>
<relativePath>../buession-springboot-parent</relativePath>
<version>2.3.1</version>
<version>2.3.2</version>
</parent>
<artifactId>buession-springboot-cache</artifactId>
<url>https://springboot.buession.com/</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
*/
package com.buession.springboot.cache.redis.autoconfigure;

import com.buession.core.converter.mapper.PropertyMapper;
import com.buession.redis.client.connection.datasource.DataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Redis 数据源 {@link DataSource} 工厂 Bean 抽象类
Expand All @@ -41,6 +44,8 @@ public abstract class AbstractDataSourceFactoryBean<DS extends DataSource> imple

protected DS dataSource;

protected final Logger logger = LoggerFactory.getLogger(getClass());

/**
* 构造函数
*
Expand All @@ -61,4 +66,27 @@ public Class<? extends DataSource> getObjectType() {
return dataSource.getClass();
}

@Override
public void afterPropertiesSet() throws Exception {
if(dataSource == null){
PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull();
dataSource = createDataSource();

propertyMapper.alwaysApplyingWhenHasText().from(properties.getClientName()).to(dataSource::setClientName);
propertyMapper.from(properties.getConnectTimeout()).as((v)->(int) v.toMillis())
.to(dataSource::setConnectTimeout);
propertyMapper.from(properties.getSoTimeout()).as((v)->(int) v.toMillis()).to(dataSource::setSoTimeout);
propertyMapper.from(properties.getInfiniteSoTimeout()).as((v)->(int) v.toMillis())
.to(dataSource::setInfiniteSoTimeout);
propertyMapper.from(properties.getPool()).to(dataSource::setPoolConfig);

if(logger.isInfoEnabled()){
logger.info("Initialized {} {} pool", dataSource.getClass().getName(),
dataSource.getPoolConfig() == null ? "without" : "with");
}
}
}

protected abstract DS createDataSource();

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
import com.buession.redis.core.RedisNode;
import com.buession.redis.core.RedisURI;
import com.buession.springboot.cache.redis.utils.RedisNodeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.BeanInitializationException;

import java.text.ParseException;
Expand All @@ -48,8 +46,6 @@
*/
class JedisDataSourceFactoryBean extends AbstractDataSourceFactoryBean<JedisRedisDataSource> {

private final static Logger logger = LoggerFactory.getLogger(JedisDataSourceFactoryBean.class);

/**
* 构造函数
*
Expand All @@ -61,26 +57,7 @@ public JedisDataSourceFactoryBean(final RedisProperties properties) {
}

@Override
public void afterPropertiesSet() throws Exception {
dataSource = createJedisDataSource();

if(Validate.hasText(properties.getClientName())){
dataSource.setClientName(properties.getClientName());
}

dataSource.setConnectTimeout((int) properties.getConnectTimeout().toMillis());
dataSource.setSoTimeout((int) properties.getSoTimeout().toMillis());
dataSource.setInfiniteSoTimeout((int) properties.getInfiniteSoTimeout().toMillis());

dataSource.setPoolConfig(properties.getPool());

if(logger.isInfoEnabled()){
logger.info("Initialized {} {} pool", dataSource.getClass().getName(),
dataSource.getPoolConfig() == null ? "without" : "with");
}
}

private JedisRedisDataSource createJedisDataSource() {
protected JedisRedisDataSource createDataSource() {
if(properties.getCluster() != null && Validate.isNotEmpty(properties.getCluster().getNodes())){
return createJedisClusterDataSource();
}else if(properties.getSentinel() != null && Validate.isNotEmpty(properties.getSentinel().getNodes())){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,21 @@ public class RedisConfiguration {

private final static Logger logger = LoggerFactory.getLogger(RedisConfiguration.class);

public RedisConfiguration(RedisProperties properties){
public RedisConfiguration(RedisProperties properties) {
this.properties = properties;
}

@Bean
@ConditionalOnBean(DataSource.class)
@ConditionalOnMissingBean
public RedisTemplate redisTemplate(ObjectProvider<DataSource> dataSource){
public RedisTemplate redisTemplate(ObjectProvider<DataSource> dataSource) {
final RedisTemplate template = new RedisTemplate(dataSource.getIfAvailable());
final Options.Builder builder = Options.Builder.getInstance()
.prefix(properties.getKeyPrefix())
.serializer(properties.getSerializer())
.enableTransactionSupport(properties.isEnableTransactionSupport());

template.setOptions(builder.build());
template.afterPropertiesSet();

if(logger.isTraceEnabled()){
logger.trace("RedisTemplate bean initialized success.");
Expand Down
Loading

0 comments on commit 656e651

Please sign in to comment.