spring boot 配置 log4j2

  1. 配置pom.xml


    org.springframework.boot
    spring-boot-starter-web


    org.springframework.boot
    spring-boot-starter-logging


    org.slf4j
    log4j-over-slf4j




    org.springframework.boot
    spring-boot-starter-test
    test


    mysql
    mysql-connector-java
    runtime


    org.springframework.boot
    spring-boot-starter-log4j2


2.log.properties
spring boot 配置 log4j2_第1张图片

  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 kv = (Map)      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();
        }
    }
}

你可能感兴趣的:(sprintboot)