package com.gblfy.controller;
import com.gblfy.service.ExceptionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@RestController
@RequestMapping("test")
public class Exception {
private final static Logger logger = LoggerFactory.getLogger(Exception.class);
@Resource
private ExceptionService exceptionService;
@GetMapping("/getException")
public boolean getException() {
boolean flag = false;
try {
flag = exceptionService.getException();
} catch (java.lang.Exception e) {
logger.error("接收 ----数据装换异常", e);
}
return flag;
}
}
package com.gblfy.service;
public interface ExceptionService {
public boolean getException() throws Exception;
}
package com.gblfy.service.impl;
import com.gblfy.service.ExceptionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
@Service
public class ExceptionServiceImpl implements ExceptionService {
private final static Logger logger = LoggerFactory.getLogger(ExceptionServiceImpl.class);
@Override
public boolean getException() throws Exception {
try {
logger.info("-----", 1 / 0);
return true;
} catch (Exception e) {
logger.error("数据装换异常", e);
throw e;
}
}
public static void main(String[] args) {
try {
logger.info("-----", 1 / 0);
} catch (Exception e) {
logger.error("数据装换异常", e);
}
System.out.println("-------------------@@@");
}
}