Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

升级springBoot #820

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ repositories {

}

def spring_version="4.3.29.RELEASE"
def spring_version="5.2.22.RELEASE"
List spring =[
"org.springframework:spring-core:$spring_version",
"org.springframework:spring-beans:$spring_version",
Expand All @@ -40,13 +40,14 @@ List spring =[

]

def spring_boot_version="1.5.22.RELEASE"
def spring_boot_version="2.3.12.RELEASE"
List spring_boot =[
"org.springframework.boot:spring-boot-starter-web:$spring_boot_version",
"org.springframework.boot:spring-boot-autoconfigure:$spring_boot_version",
"org.springframework.boot:spring-boot-configuration-processor:$spring_boot_version",
"org.springframework.boot:spring-boot-starter-data-jpa:$spring_boot_version",
"org.springframework.boot:spring-boot-starter-amqp:$spring_boot_version"
"org.springframework.boot:spring-boot-starter-amqp:$spring_boot_version",
"org.springframework.boot:spring-boot-starter-validation:$spring_boot_version"
]


Expand All @@ -56,7 +57,7 @@ List swagger = [
]


def log4j_version="2.15.0"
def log4j_version="2.18.0"
List logger = [
"org.apache.logging.log4j:log4j-api:$log4j_version",
"org.apache.logging.log4j:log4j-core:$log4j_version",
Expand All @@ -71,12 +72,13 @@ List jaxb = [
"javax.activation:activation:1.1.1"
]

def jackson_version = "2.11.4"
def jackson_version = "2.14.1"
List jackson = [
"com.fasterxml.jackson.core:jackson-annotations:$jackson_version",
"com.fasterxml.jackson.core:jackson-core:$jackson_version",
"com.fasterxml.jackson.core:jackson-databind:$jackson_version",
"com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jackson_version"
"com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jackson_version",
"com.fasterxml.jackson.core:jackson-databind:$jackson_version"
]

// cover old version
Expand Down Expand Up @@ -107,6 +109,7 @@ dependencies {
compile 'com.github.jsqlparser:jsqlparser:2.0'
compile 'org.apache.commons:commons-lang3:3.8.1'
compile 'org.slf4j:jcl-over-slf4j:1.7.30'
compile 'org.apache.httpcomponents:httpclient:4.5.14'
// cover low version guava
compile 'com.google.guava:guava:29.0-jre'
testCompile('org.springframework.boot:spring-boot-starter-test') {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/webank/webase/front/abi/AbiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public BasePageResponse getAbiListByGroupId(@PathVariable("groupId") Integer gro
if (pageNumber < 1) {
throw new FrontException(ConstantCode.PARAM_ERROR);
}
Pageable pageable = new PageRequest(pageNumber - 1, pageSize,
new Sort(Sort.Direction.DESC, "createTime"));
Pageable pageable = PageRequest.of(pageNumber - 1, pageSize,
Sort.by(Sort.Direction.DESC, "createTime"));
resList = abiService.getListByGroupId(groupId, pageable);

log.debug("end getAbiListByGroupId resList count. {}", resList.size());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/webank/webase/front/abi/AbiService.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void updateAbiInfo(ReqImportAbi param) {

public void delete(Long id) {
checkAbiIdExist(id);
abiRepository.delete(id);
abiRepository.deleteById(id);
}

public AbiInfo getAbiById(Long abiId) {
Expand Down
51 changes: 25 additions & 26 deletions src/main/java/com/webank/webase/front/base/config/TomcatConfig.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
package com.webank.webase.front.base.config;

import com.webank.webase.front.base.properties.Constants;
import org.apache.coyote.http11.Http11NioProtocol;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class TomcatConfig {

@Autowired
Constants constantProperties;
@Bean
public EmbeddedServletContainerFactory createEmbeddedServletContainerFactory() {
TomcatEmbeddedServletContainerFactory tomcatFactory = new TomcatEmbeddedServletContainerFactory();
tomcatFactory.addConnectorCustomizers(connector -> {
Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
protocol.setKeepAliveTimeout(constantProperties.getKeepAliveTimeout()* 1000);
protocol.setMaxKeepAliveRequests(constantProperties.getKeepAliveRequests());
});
return tomcatFactory;
}
}
//package com.webank.webase.front.base.config;
//
//import com.webank.webase.front.base.properties.Constants;
//import org.apache.coyote.http11.Http11NioProtocol;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//@Configuration
//public class TomcatConfig {
//
// @Autowired
// Constants constantProperties;
// @Bean
// public TomcatServletWebServerFactory createEmbeddedServletContainerFactory() {
// TomcatServletWebServerFactory tomcatFactory = new TomcatServletWebServerFactory();
// tomcatFactory.addConnectorCustomizers(connector -> {
// Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
// protocol.setKeepAliveTimeout(constantProperties.getKeepAliveTimeout()* 1000);
// protocol.setMaxKeepAliveRequests(constantProperties.getKeepAliveRequests());
// });
// return tomcatFactory;
// }
//}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import java.util.List;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import com.webank.webase.front.contract.entity.Contract;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ public void deleteContract(Long contractId, int groupId) {
// check contract id
verifyContractIdExist(contractId, groupId);
// remove
contractRepository.delete(contractId);
contractRepository.deleteById(contractId);
log.debug("end deleteContract");
}

Expand Down Expand Up @@ -619,7 +619,7 @@ public Page<Contract> findContractByPage(ReqPageContract param) throws IOExcepti
// page start from index 1 instead of 0
int pageNumber = param.getPageNumber() - 1;
Pageable pageable =
new PageRequest(pageNumber, param.getPageSize(), Direction.DESC, "modifyTime");
PageRequest.of(pageNumber, param.getPageSize(), Direction.DESC, "modifyTime");
Page<Contract> contractPage = contractRepository.findAll(
(Root<Contract> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) -> {
// v1.4.2, param add contractPath to filter
Expand Down Expand Up @@ -867,7 +867,7 @@ public boolean accept(File dir, String fileName) {
*/
public ContractPath addContractPath(ReqContractPath req) {
ContractPathKey pathKey = new ContractPathKey(req.getGroupId(), req.getContractPath());
ContractPath check = contractPathRepository.findOne(pathKey);
ContractPath check = contractPathRepository.findById(pathKey).orElse(null);
if (check != null) {
log.error("addContractPath fail, path exists check:{}", check);
throw new FrontException(ConstantCode.CONTRACT_PATH_IS_EXISTS);
Expand All @@ -888,7 +888,7 @@ public List<ContractPath> findPathList(Integer groupId) throws IOException {
// init default contracts and dir
initDefaultContract(groupId);
// get from database
Sort sort = new Sort(Sort.Direction.DESC, "modifyTime");
Sort sort = Sort.by(Sort.Direction.DESC, "modifyTime");
List<ContractPath> contractPaths = contractPathRepository.findAll((Root<ContractPath> root,
CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) -> {
Predicate predicate = criteriaBuilder.equal(root.get("groupId"), groupId);
Expand All @@ -904,7 +904,7 @@ public void deletePath(Integer groupId, String contractPath) {
ContractPathKey contractPathKey = new ContractPathKey();
contractPathKey.setGroupId(groupId);
contractPathKey.setContractPath(contractPath);
contractPathRepository.delete(contractPathKey);
contractPathRepository.deleteById(contractPathKey);
}

/**
Expand Down Expand Up @@ -943,14 +943,14 @@ public void batchDeleteByPath(int groupId, String contractPath) {
List<Contract> contractList =
contractRepository.findByGroupIdAndContractPath(groupId, contractPath);
log.debug("batchDeleteByPath delete contracts");
contractList.forEach(c -> contractRepository.delete(c.getId()));
contractList.forEach(c -> contractRepository.deleteById(c.getId()));
log.debug("batchDeleteByPath delete contracts");
contractPathRepository.delete(new ContractPathKey(groupId, contractPath));
contractPathRepository.deleteById(new ContractPathKey(groupId, contractPath));
log.debug("batchDeleteByPath delete contract path");
}

public Contract findById(Long contractId) {
Contract contract = contractRepository.findOne(contractId);
Contract contract = contractRepository.findById(contractId).orElse(null);
if (Objects.isNull(contract)) {
throw new FrontException(ConstantCode.INVALID_CONTRACT_ID);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
Expand Down Expand Up @@ -84,7 +85,7 @@ public void insertStoreItem(long storeId, String storeName, String StoreName_en,
String StoreDetail_en)
{
log.info("insert storeItem id:{},storeName:{}", storeId, storeName);
if (contractStoreRepository.exists(storeId)) {
if (contractStoreRepository.existsById(storeId)) {
log.info("insertStoreItem skip storeId:{} already exist", storeId);
return;
}
Expand Down Expand Up @@ -155,7 +156,7 @@ public void insertContractFolderItem(long contractFolderId, long storeId, String
String contractFolderDesc_en, String contractFolderDetail_en)
{
log.info("insert contractFolderItem id:{},contractFolderName:{} ", contractFolderId, contractFolderName);
if (contractFolderRepository.exists(contractFolderId)) {
if (contractFolderRepository.existsById(contractFolderId)) {
log.info("insertContractFolderItem skip contractFolderId:{} already exist", contractFolderId);
return;
}
Expand Down Expand Up @@ -289,7 +290,7 @@ public void insertContractItem(long contractId, long contractFolderId, String co
String contractDesc, String contractDesc_en)
{
log.info("insert contractItem id:{},contractName:{}", contractId, contractName);
if (contractItemRepository.exists(contractId)) {
if (contractItemRepository.existsById(contractId)) {
log.info("insertContractItem skip contractId:{} already exist", contractId);
return;
}
Expand Down Expand Up @@ -327,13 +328,13 @@ public void readAndInitStoreItem() {
}
List<StoreItem> item2Save = new ArrayList<>();
for (StoreItem item : storeItems) {
if (!contractStoreRepository.exists(item.getStoreId())) {
if (!contractStoreRepository.existsById(item.getStoreId())) {
item.setCreateTime(LocalDateTime.now());
item.setModifyTime(item.getCreateTime());
item2Save.add(item);
}
}
contractStoreRepository.save(item2Save);
contractStoreRepository.saveAll(item2Save);
log.info("readAndInitStoreItem save {} items", storeItems.size());
}

Expand All @@ -346,13 +347,13 @@ public void readAndInitFolderItem() {
}
List<ContractFolderItem> item2Save = new ArrayList<>();
for (ContractFolderItem item : folderItems) {
if (!contractFolderRepository.exists(item.getContractFolderId())) {
if (!contractFolderRepository.existsById(item.getContractFolderId())) {
item.setCreateTime(LocalDateTime.now());
item.setModifyTime(item.getCreateTime());
item2Save.add(item);
}
}
contractFolderRepository.save(item2Save);
contractFolderRepository.saveAll(item2Save);
log.info("readAndInitFolderItem save {} items", folderItems.size());
}

Expand All @@ -365,13 +366,13 @@ public void readAndInitContractItem() {
}
List<ContractItem> item2Save = new ArrayList<>();
for (ContractItem item : contractItems) {
if (!contractItemRepository.exists(item.getContractId())) {
if (!contractItemRepository.existsById(item.getContractId())) {
item.setCreateTime(LocalDateTime.now());
item.setModifyTime(item.getCreateTime());
item2Save.add(item);
}
}
contractItemRepository.save(item2Save);
contractItemRepository.saveAll(item2Save);
log.info("readAndInitContractItem save {} items", contractItems.size());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
public interface ContractEventInfoRepository extends CrudRepository<ContractEventInfo, String>,
JpaSpecificationExecutor<ContractEventInfo> {

ContractEventInfo findById(String id);

List<ContractEventInfo> findByAppId(String appId);

List<ContractEventInfo> findByGroupId(int groupId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ public BasePageResponse getNewBlockEventInfo(@PathVariable("groupId") Integer gr
if (pageNumber < 1) {
return new BasePageResponse(ConstantCode.PARAM_ERROR, null, 0);
}
Pageable pageable = new PageRequest(pageNumber - 1, pageSize,
new Sort(Sort.Direction.DESC, "createTime"));
Pageable pageable = PageRequest.of(pageNumber - 1, pageSize,
Sort.by(Sort.Direction.DESC, "createTime"));
resList = eventService.getNewBlockInfoList(groupId, pageable);
}
log.debug("end getNewBlockEventInfo resList count. {}", resList.size());
Expand Down Expand Up @@ -227,8 +227,8 @@ public BasePageResponse getContractEventInfo(@PathVariable("groupId") Integer gr
if (pageNumber < 1) {
return new BasePageResponse(ConstantCode.PARAM_ERROR, null, 0);
}
Pageable pageable = new PageRequest(pageNumber - 1, pageSize,
new Sort(Sort.Direction.DESC, "createTime"));
Pageable pageable = PageRequest.of(pageNumber - 1, pageSize,
Sort.by(Sort.Direction.DESC, "createTime"));
resList = eventService.getContractEventInfoList(groupId, pageable);
}
log.debug("end getContractEventInfo resList count. {}", resList.size());
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/webank/webase/front/event/EventService.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public List<NewBlockEventInfo> unregisterNewBlock(String infoId, String appId, i
String queueName) {
log.debug("unregisterNewBlock appId:{},groupId:{},exchangeName:{},queueName:{}",
appId, groupId, exchangeName, queueName);
NewBlockEventInfo eventInfo = newBlockEventInfoRepository.findById(infoId);
NewBlockEventInfo eventInfo = newBlockEventInfoRepository.findById(infoId).orElse(null);;
if (Objects.isNull(eventInfo)) {
throw new FrontException(ConstantCode.DATA_NOT_EXIST_ERROR);
}
Expand All @@ -310,7 +310,7 @@ public List<NewBlockEventInfo> unregisterNewBlock(String infoId, String appId, i
throw new FrontException(ConstantCode.UNREGISTER_FAILED_ERROR);
}
// remove from db
newBlockEventInfoRepository.delete(infoId);
newBlockEventInfoRepository.deleteById(infoId);
return newBlockEventInfoRepository.findByAppId(appId);
}

Expand Down Expand Up @@ -347,7 +347,7 @@ public List<ContractEventInfo> unregisterContractEvent(String infoId, String app
String queueName) {
log.debug("unregisterContractEvent infoId:{},appId:{},groupId:{},exchangeName:{},queueName:{}",
infoId, appId, groupId, exchangeName, queueName);
ContractEventInfo eventInfo = contractEventInfoRepository.findById(infoId);
ContractEventInfo eventInfo = contractEventInfoRepository.findById(infoId).orElse(null);;
if (Objects.isNull(eventInfo)) {
throw new FrontException(ConstantCode.DATA_NOT_EXIST_ERROR);
}
Expand All @@ -367,7 +367,7 @@ public List<ContractEventInfo> unregisterContractEvent(String infoId, String app
throw new FrontException(ConstantCode.UNREGISTER_FAILED_ERROR);
}
// remove from db
contractEventInfoRepository.delete(infoId);
contractEventInfoRepository.deleteById(infoId);
return contractEventInfoRepository.findByAppId(appId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
public interface NewBlockEventInfoRepository extends CrudRepository<NewBlockEventInfo, String>,
JpaSpecificationExecutor<NewBlockEventInfo> {

NewBlockEventInfo findById(String id);

List<NewBlockEventInfo> findByGroupIdAndAppId(int groupId, String appId);

List<NewBlockEventInfo> findByAppId(String appId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public class KeyStoreService {
* without external user
*/
public List<KeyStoreInfo> getLocalKeyStoreList() {
Sort sort = new Sort(Sort.Direction.ASC, "userName");
Sort sort = Sort.by(Sort.Direction.ASC, "userName");
List<KeyStoreInfo> keyStores = keystoreRepository.findAll(
(Root<KeyStoreInfo> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) -> {
Predicate predicate = criteriaBuilder.equal(root.get("type"), KeyTypes.LOCALUSER.getValue());
Expand Down Expand Up @@ -179,7 +179,7 @@ private KeyStoreInfo saveSignKeyStore(RspUserInfo rspUserInfo) {
* deleteKeyStore.
*/
public void deleteKeyStore(String address) {
keystoreRepository.delete(address);
keystoreRepository.deleteById(address);
}

/**
Expand Down
Loading