Commit 73c8f640 by 仲光辉

切入点表达式修正:@Annotation -->@within 2020/10/20 10:21

parent f08ada1e
...@@ -13,17 +13,11 @@ import java.lang.annotation.Target; ...@@ -13,17 +13,11 @@ import java.lang.annotation.Target;
* <p> * <p>
* 此注解标注使用在标有诸如: * 此注解标注使用在标有诸如:
* <br/> * <br/>
* - {@link org.springframework.web.bind.annotation.RequestMapping} * - {@link org.springframework.web.bind.annotation.RestController}
* <br/> * <br/>
* - {@link org.springframework.web.bind.annotation.GetMapping} * - {@link org.springframework.stereotype.Controller}
* <br/> * <br/>
* - {@link org.springframework.web.bind.annotation.PostMapping} * 等 SpringMVC Application Controller注解的类上 用于记录 请求日志 和 处理请求异常日志
* <br/>
* - {@link org.springframework.web.bind.annotation.PutMapping}
* <br/>
* - {@link org.springframework.web.bind.annotation.DeleteMapping}
* </p>
* 等 SpringMVC 处理器方法注解的方法上 用于记录 请求日志 和 处理请求异常日志
* <br/> * <br/>
* <br/> * <br/>
* 当前注解{@link DoRequestLog} 是 Request日志切面${@link RequestLogAspect} 的 切入点表达式 * 当前注解{@link DoRequestLog} 是 Request日志切面${@link RequestLogAspect} 的 切入点表达式
...@@ -41,7 +35,7 @@ import java.lang.annotation.Target; ...@@ -41,7 +35,7 @@ import java.lang.annotation.Target;
* @create 2020/10/19 * @create 2020/10/19
* @see RequestLogAspect * @see RequestLogAspect
*/ */
@Target({ElementType.METHOD}) @Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface DoRequestLog { public @interface DoRequestLog {
......
...@@ -44,7 +44,7 @@ public class RequestLogAspect { ...@@ -44,7 +44,7 @@ public class RequestLogAspect {
/** /**
* 切入点表达式 * 切入点表达式
*/ */
@Pointcut("@annotation(cn.dankal.test.common.service.aspect.DoRequestLog)") @Pointcut("@within(cn.dankal.test.common.service.aspect.DoRequestLog)")
public void pointcut() { public void pointcut() {
} }
......
...@@ -9,6 +9,9 @@ import org.springframework.web.bind.annotation.PathVariable; ...@@ -9,6 +9,9 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
/** /**
* {@link RestController} * {@link RestController}
* UserController * UserController
...@@ -18,6 +21,7 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -18,6 +21,7 @@ import org.springframework.web.bind.annotation.RestController;
* @create 2020/10/18 * @create 2020/10/18
*/ */
@Slf4j @Slf4j
@DoRequestLog
@RestController @RestController
@RequestMapping("/user") @RequestMapping("/user")
public class UserController { public class UserController {
...@@ -31,7 +35,6 @@ public class UserController { ...@@ -31,7 +35,6 @@ public class UserController {
this.orderServiceClient = orderServiceClient; this.orderServiceClient = orderServiceClient;
} }
@DoRequestLog
@GetMapping("/{userId}") @GetMapping("/{userId}")
public Person getUserById(@PathVariable("userId") Long userId) { public Person getUserById(@PathVariable("userId") Long userId) {
log.info("user service 01 get user: {}", userId); log.info("user service 01 get user: {}", userId);
...@@ -41,4 +44,11 @@ public class UserController { ...@@ -41,4 +44,11 @@ public class UserController {
.setName("ZGH.MercyModest") .setName("ZGH.MercyModest")
.setOther("user-service-01 --> " + orderId); .setOther("user-service-01 --> " + orderId);
} }
@RequestMapping("/test/info")
public String getTestInfo() {
String timeFormatString = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now());
String orderSimpleInfo = orderServiceClient.testGetSimpleInfo();
return timeFormatString +" --> "+ orderSimpleInfo;
}
} }
...@@ -9,6 +9,9 @@ import org.springframework.web.bind.annotation.PathVariable; ...@@ -9,6 +9,9 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
/** /**
* {@link RestController} * {@link RestController}
* UserController * UserController
...@@ -18,6 +21,7 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -18,6 +21,7 @@ import org.springframework.web.bind.annotation.RestController;
* @create 2020/10/18 * @create 2020/10/18
*/ */
@Slf4j @Slf4j
@DoRequestLog
@RestController @RestController
@RequestMapping("/user") @RequestMapping("/user")
public class UserController { public class UserController {
...@@ -31,7 +35,6 @@ public class UserController { ...@@ -31,7 +35,6 @@ public class UserController {
this.orderServiceClient = orderServiceClient; this.orderServiceClient = orderServiceClient;
} }
@DoRequestLog
@GetMapping("/{userId}") @GetMapping("/{userId}")
public Person getUserById(@PathVariable("userId") Long userId) throws Throwable { public Person getUserById(@PathVariable("userId") Long userId) throws Throwable {
if (1 == userId) { if (1 == userId) {
...@@ -45,4 +48,10 @@ public class UserController { ...@@ -45,4 +48,10 @@ public class UserController {
.setName("ZGH.MercyModest") .setName("ZGH.MercyModest")
.setOther("user-service-02 --> " + orderId); .setOther("user-service-02 --> " + orderId);
} }
@RequestMapping("/test/info")
public String getTestInfo() {
String timeFormatString = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now());
String orderSimpleInfo = orderServiceClient.testGetSimpleInfo();
return timeFormatString +" --> "+ orderSimpleInfo;
}
} }
...@@ -19,15 +19,20 @@ import java.util.UUID; ...@@ -19,15 +19,20 @@ import java.util.UUID;
* @create 2020/10/18 * @create 2020/10/18
*/ */
@Slf4j @Slf4j
@DoRequestLog
@RestController @RestController
@RequestMapping("/order") @RequestMapping("/order")
public class OrderController { public class OrderController {
@DoRequestLog
@GetMapping("/{userId}") @GetMapping("/{userId}")
public String getOrderId(@PathVariable("userId") Long userId) { public String getOrderId(@PathVariable("userId") Long userId) {
log.info("order service 01 getOrderId: {}", userId); log.info("order service 01 getOrderId: {}", userId);
return "order service 01 "+userId + " --> "+ UUID.randomUUID().toString().replace("-", ""); return "order service 01 " + userId + " --> " + UUID.randomUUID().toString().replace("-", "");
}
@GetMapping("/test/info")
public String testGetSimpleInfo() {
return UUID.randomUUID().toString().replace("-", "");
} }
} }
...@@ -19,11 +19,11 @@ import java.util.UUID; ...@@ -19,11 +19,11 @@ import java.util.UUID;
* @create 2020/10/18 * @create 2020/10/18
*/ */
@Slf4j @Slf4j
@DoRequestLog
@RestController @RestController
@RequestMapping("/order") @RequestMapping("/order")
public class OrderController { public class OrderController {
@DoRequestLog
@GetMapping("/{userId}") @GetMapping("/{userId}")
public String getOrderId(@PathVariable("userId") Long userId) { public String getOrderId(@PathVariable("userId") Long userId) {
log.info("order service 02 getOrderId: {}", userId); log.info("order service 02 getOrderId: {}", userId);
...@@ -33,4 +33,9 @@ public class OrderController { ...@@ -33,4 +33,9 @@ public class OrderController {
return "order service 02 "+userId + " --> "+ UUID.randomUUID().toString().replace("-", ""); return "order service 02 "+userId + " --> "+ UUID.randomUUID().toString().replace("-", "");
} }
@GetMapping("/test/info")
public String testGetSimpleInfo() {
return UUID.randomUUID().toString().replace("-", "");
}
} }
...@@ -23,4 +23,12 @@ public interface OrderServiceClient { ...@@ -23,4 +23,12 @@ public interface OrderServiceClient {
*/ */
@GetMapping("/order/{userId}") @GetMapping("/order/{userId}")
String getOrderId(@PathVariable("userId") Long userId); String getOrderId(@PathVariable("userId") Long userId);
/**
* 测试获取 测试信息
*
* @return UUID String
*/
@GetMapping("/order/test/info")
String testGetSimpleInfo();
} }
...@@ -18,4 +18,9 @@ public class OrderServiceClientFallback implements OrderServiceClient { ...@@ -18,4 +18,9 @@ public class OrderServiceClientFallback implements OrderServiceClient {
public String getOrderId(Long userId) { public String getOrderId(Long userId) {
return "return from OrderServiceClientFallback:getOrderId:" + userId; return "return from OrderServiceClientFallback:getOrderId:" + userId;
} }
@Override
public String testGetSimpleInfo() {
return "return from OrderServiceClientFallback: null";
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment