终于解决了,exceptionhandle未生效。。。问题

master
kezhen 2 years ago
parent 7d5096823d
commit b407484298

@ -6,6 +6,22 @@
<synchronize>true</synchronize>
<jdbc-driver>org.mariadb.jdbc.Driver</jdbc-driver>
<jdbc-url>jdbc:mariadb://192.168.1.8:3306/beacon_cloud</jdbc-url>
<vm-options>&quot;-Djdk.tls.disabledAlgorithms=SSLv3, TLSv1, RC4, DES, MD5withRSA, DH keySize &lt; 1024, EC keySize &lt; 224, 3DES_EDE_CBC, anon, NULL, include jdk.disabled.namedCurves&quot;</vm-options>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
<data-source source="LOCAL" name="beacon_cloud@10.3.10.36" uuid="eb6a0856-57db-40a3-9bc9-03010b437c89">
<driver-ref>mysql.8</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
<jdbc-url>jdbc:mysql://10.3.10.36:3306/beacon_cloud</jdbc-url>
<vm-options>&quot;-Djdk.tls.disabledAlgorithms=SSLv3, TLSv1, RC4, DES, MD5withRSA, DH keySize &lt; 1024, EC keySize &lt; 224, 3DES_EDE_CBC, anon, NULL, include jdk.disabled.namedCurves&quot;</vm-options>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
<data-source source="LOCAL" name="beacon_cloud@101.42.1.196" uuid="946e7778-d82b-4376-99e6-031c7e491d16">
<driver-ref>mysql_aurora</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.mariadb.jdbc.Driver</jdbc-driver>
<jdbc-url>jdbc:mariadb://101.42.1.196:3306/beacon_cloud</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>

@ -3,6 +3,7 @@
<component name="Encoding">
<file url="file://$PROJECT_DIR$/beacon-cache/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/beacon-common/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/beacon-exception-test/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/beacon-test/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/beancon-api/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />

@ -7,6 +7,11 @@
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
<option name="ignoredFiles">
<set>
<option value="$PROJECT_DIR$/beacon-exception-test/pom.xml" />
</set>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />

@ -6,8 +6,10 @@ spring:
cloud:
nacos:
config:
server-addr: 192.168.1.8:8848
# server-addr: 192.168.1.8:8848
server-addr: 10.3.10.36:8848
file-extension: yml
# beacon-cache-dev.yml
discovery:
server-addr: 192.168.1.8:8848
# server-addr: 192.168.1.8:8848
server-addr: 10.3.10.36:8848

@ -1,4 +1,4 @@
package com.mashibing.constant;
package com.mashibing.common.constant;
/**
*

@ -1,6 +1,6 @@
package com.mashibing.exceptiion;
package com.mashibing.common.exception;
import com.mashibing.enums.ExceptionEnums;
import com.mashibing.common.enums.ExceptionEnums;
import lombok.Getter;
/**

@ -9,24 +9,6 @@ public class ClientBalance {
private java.sql.Timestamp created;
private long createId;
@Override
public String toString() {
return "ClientBalance{" +
"id=" + id +
", clientId=" + clientId +
", balance=" + balance +
", created=" + created +
", createId=" + createId +
", updated=" + updated +
", updateId=" + updateId +
", isDelete=" + isDelete +
", extend1='" + extend1 + '\'' +
", extend2='" + extend2 + '\'' +
", extend3='" + extend3 + '\'' +
", extend4='" + extend4 + '\'' +
'}';
}
private java.sql.Timestamp updated;
private long updateId;
private long isDelete;
@ -143,4 +125,21 @@ public class ClientBalance {
this.extend4 = extend4;
}
@Override
public String toString() {
return "ClientBalance{" +
"id=" + id +
", clientId=" + clientId +
", balance=" + balance +
", created=" + created +
", createId=" + createId +
", updated=" + updated +
", updateId=" + updateId +
", isDelete=" + isDelete +
", extend1='" + extend1 + '\'' +
", extend2='" + extend2 + '\'' +
", extend3='" + extend3 + '\'' +
", extend4='" + extend4 + '\'' +
'}';
}
}

@ -4,12 +4,11 @@ import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
/**
* @author kezhen
* @date 2022/12/28
* @description
* @Author kezhen
* @Date 2022-12-29
* @Description
*/
public interface ClientBalanceMapper {
@Select("select balance from client_balance where client_id = #{clientId}")
Long findByClientId(@Param("clientId") Integer clientId);
@Select("select balance from client_balance WHERE id = #{clientId}")
Integer findBalanceByid(@Param("clientId") Integer clientId);
}

@ -4,10 +4,12 @@ spring:
cloud:
nacos:
discovery:
server-addr: 192.168.1.8:8848
# server-addr: 192.168.1.8:8848
server-addr: 192.168.56.10:8848
datasource:
driver-class-name: org.gjt.mm.mysql.Driver
url: jdbc:mysql://192.168.1.8:3306/beacon_cloud?characterEncoding=utf-8
# url: jdbc:mysql://192.168.1.8:3306/beacon_cloud?characterEncoding=utf-8
url: jdbc:mysql://192.168.56.10:3306/beacon_cloud?characterEncoding=utf-8
username: root
password: ZhengJinWei123!

@ -1,6 +1,5 @@
package com.mashibing.test.mapper;
import com.mashibing.test.client.CacheClient;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@ -10,9 +9,9 @@ import org.springframework.test.context.junit4.SpringRunner;
import static org.junit.Assert.*;
/**
* @author kezhen
* @date 2022/12/28
* @description
* @Author kezhen
* @Date 2022-12-29
* @Description
*/
@SpringBootTest
@RunWith(SpringRunner.class)
@ -20,14 +19,9 @@ public class ClientBalanceMapperTest {
@Autowired
private ClientBalanceMapper clientBalanceMapper;
@Autowired
private CacheClient cacheClient;
@Test
public void findByClientId() {
Long balance = clientBalanceMapper.findByClientId(1);
System.out.println("balance = " + balance);
cacheClient.set("client_balance:1", balance);
public void findBalanceByid() {
Integer balanceByid = clientBalanceMapper.findBalanceByid(1);
System.out.println("balanceByid = " + balanceByid);
}
}

@ -1,22 +1,23 @@
package com.mashibing.advice;
package com.mashibing.api.advice;
import com.mashibing.api.util.R;
import com.mashibing.api.vo.ResultVO;
import com.mashibing.exceptiion.ApiException;
import com.mashibing.common.exception.ApiException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
/**
* @author kezhen
* @date 2022/12/29
* @author zjw
* @description
*/
@RestControllerAdvice
public class ApiExceptionHander {
public class ApiExceptionHandler{
@ExceptionHandler(ApiException.class)
public ResultVO apiException(ApiException ex){
System.out.println("exception.getCode() = " + ex.getCode());
System.out.println("ApiExceptionHandler.apiException");
return R.error(ex);
}
}

@ -5,7 +5,7 @@ import com.mashibing.api.from.SingleSendForm;
import com.mashibing.api.util.R;
import com.mashibing.api.vo.ResultVO;
import com.mashibing.common.model.StandardSubmit;
import com.mashibing.enums.ExceptionEnums;
import com.mashibing.common.enums.ExceptionEnums;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

@ -10,7 +10,7 @@ public interface CheckFilter {
/**
*
* @param standardSubmit
* @param submit
*/
void check(StandardSubmit submit);
}

@ -2,10 +2,10 @@ package com.mashibing.api.filter.impl;
import com.mashibing.api.client.BeaconCacheClient;
import com.mashibing.api.filter.CheckFilter;
import com.mashibing.common.constant.CacheConstant;
import com.mashibing.common.enums.ExceptionEnums;
import com.mashibing.common.exception.ApiException;
import com.mashibing.common.model.StandardSubmit;
import com.mashibing.constant.CacheConstant;
import com.mashibing.enums.ExceptionEnums;
import com.mashibing.exceptiion.ApiException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -13,25 +13,31 @@ import org.springframework.stereotype.Service;
import java.util.Map;
/**
* @author kezhen
* @description
* @author zjw
* @description apikey
*/
@Service(value = "apikey")
@Slf4j
public class ApiKeyCheckFilter implements CheckFilter {
@Autowired
private BeaconCacheClient beaconCacheClient;
private BeaconCacheClient cacheClient;
@Override
public void check(StandardSubmit submit) {
log.info("【接口模块-校验apikey】 校验ing…………");
Map clientBusiness = beaconCacheClient.hGetAll(CacheConstant.CLIENT_BUSINESS + submit.getApikey());
if (clientBusiness == null || clientBusiness.size() == 0) {
log.info("【接口模块-校验apikey】 非法的apikey = {}", submit.getApikey());
//1. 基于cacheClient查询客户信息
Map clientBusiness = cacheClient.hGetAll(CacheConstant.CLIENT_BUSINESS + submit.getApikey());
//2. 如果为null直接扔异常
if(clientBusiness == null || clientBusiness.size() == 0){
log.info("【接口模块-校验apikey】 非法的apikey = {}",submit.getApikey());
throw new ApiException(ExceptionEnums.ERROR_APIKEY);
}
submit.setCliendId((Long) clientBusiness.get("id"));
log.info("【接口模块-校验apikey】 查询到客户信息 clientBusiness= {}", clientBusiness);
//3. 正常封装数据
// submit.setClientId(Long.parseLong(clientBusiness.get("id") + ""));
log.info("【接口模块-校验apikey】 查询到客户信息 clientBusiness = {}",clientBusiness);
}
}

@ -1,7 +1,7 @@
package com.mashibing.api.util;
import com.mashibing.api.vo.ResultVO;
import com.mashibing.exceptiion.ApiException;
import com.mashibing.common.exception.ApiException;
/**
* @author kezhen

@ -9,10 +9,12 @@ spring:
nacos:
# nacos注册中心地址
discovery:
server-addr: 192.168.1.8:8848
# server-addr: 192.168.1.8:8848
server-addr: 10.3.10.36:8848
# nacos配置中心地址
config:
server-addr: 192.168.1.8:8848
# server-addr: 192.168.1.8:8848
server-addr: 10.3.10.36:8848
file-extension: yml
# beacon-api-dev.yml

Loading…
Cancel
Save