spring boot 配置 log4j2

  1. 配置pom.xml
    <dependencies>
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
    <exclusion>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-logging</artifactId>
    </exclusion>
    <exclusion>
    <groupId>org.slf4j</groupId>
    <artifactId>log4j-over-slf4j</artifactId>
    </exclusion>
    </exclusions>
    </dependency>
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
    </dependency>
    <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <scope>runtime</scope>
    </dependency>
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-log4j2</artifactId>
    </dependency>
    </dependencies>

2.log.properties
这里写图片描述

  1. 列表内容
package com.gzhpay.control;
import com.gzhpay.reqBusiness.*;
import com.hy.pmp.client.DefaultNoCardPayClient;
import com.hy.utils.JsonUtil;
import com.hy.utils.StringUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
@RestController
public class CommonClient {
    @Value("${serviceUrl}")
    private String serviceUrl ;
    @Value("${version}")
    private String version;
    @Value("${encoding}")
    private String encoding ;

    private static final Logger L= LogManager.getLogger(CommonClient.class.getName());

    @RequestMapping("/get")
    public  void payment(HttpServletRequest request, HttpServletResponse response, Model model){

         L.debug("--------支付——————————————————————————————————");
         L.info("--------支付1——————————————————————————————————");
        L.error("hello");
         String payType = request.getParameter("payType");
        //String privateKeyPath = CommonClient.class.getClassLoader().getResource("pra.pem");
        String privateKeyPath = this.getClass().getClassLoader().getResource("pkcs8_pra.pem").getPath() ;
        //String privateKeyPath="F:/workspace/gzhpay/target/classes/pra.key";
        System.out.println(privateKeyPath);
        String publicKeyPath = this.getClass().getClassLoader().getResource("pub.key").getPath();
        //String publicKeyPath ="F:/workspace/gzhpay/target/classes/pub.key";
        String msgBody=null;
        String tranAmt="0.00";
        String auth_code;
        //1.初始化发送报文
        DefaultNoCardPayClient client = new DefaultNoCardPayClient(version,encoding,privateKeyPath,publicKeyPath);
        System.out.println("**************************************************************************************1");
        //2.组装Json字符串格式的报文体
        switch (payType)
        {
            case "0":
                tranAmt = String.valueOf((int)(Double.parseDouble(request.getParameter("tranAmt"))*100));
                msgBody = OrderCreateBusiness.assembleMsgBody(tranAmt);//创建订单号
                break;
            case "1":
                auth_code = request.getParameter("auth_code");
                msgBody = CancelBusiness.assembleMsgBody(); //扫码撤销
                break;
            case "2":
                msgBody = RefundBusiness.assembleMsgBody(); //扫码退货
                break;
            case "3":
                msgBody = ReversalBusiness.assembleMsgBody(); //扫码冲正
                break;
            case "4":
                msgBody = OfficialBusiness.assembleMsgBody(); //公众号/服务窗支付
                break;
            case "5":
                msgBody = ScanCodeQuery.assembleMsgBody(); //扫码结果查询
                break;
            default:
        }
        //3.发送交易
        System.out.println(msgBody);
        String responseBody = client.execute(serviceUrl,msgBody);
        //3.交易异常时获取错误信息
        if(StringUtil.isEmpty(responseBody)){
            String err = client.getErrorMessage();
            System.out.println(err);
        }else{
            System.out.println(responseBody);
            Map<String, Object> kv = (Map<String, Object>)      JsonUtil.fromJsonToObj(responseBody, Map.class);
            String resp_cd = kv.get("resp_cd").toString();
            System.out.println("resp_cd:"+resp_cd);
        //  String qr_code = kv.get("qr_code").toString();
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值