2021
11-01
11-01
Spring Aop 如何获取参数名参数值
前言:有时候我们在用SpringAop面向切面编程,需要获取连接点(JoinPoint)方法参数名、参数值。环境:MacOSXIntellijIDEASpringBoot2xJdk1.8xCode:packagecom.example.aopdemo.aop;importlombok.extern.slf4j.Slf4j;importorg.aspectj.lang.ProceedingJoinPoint;importorg.aspectj.lang.annotation.Around;importorg.aspectj.lang.annotation.Aspect;importorg.aspectj.lang.reflect.CodeSignature;i...
继续阅读 >
1.切所有controller下的请求项目结构任意公共方法的执行:execution(public*(…))##public可以省略,第一个代表方法的任意返回值第二个参数代表任意包+类+方法(…)任意参数配置切入点:@Pointcut("execution(*com.gcol.qy.web.system.controller..*.*(..))")publicvoidconPoint(){}表达式结构解释如下:标识符含义execution()表达...
SpringBoot+SpringSecurity无法实现跨域未使用Security时跨域:importorg.slf4j.Logger;importorg.slf4j.LoggerFactory;importorg.springframework.beans.factory.annotation.Value;importorg.springframework.boot.autoconfigure.AutoConfigureBefore;importorg.springframework.context.annotation.Configuration;importorg.springframework.format.FormatterRegistry;importorg.springframework.web.servlet.config.ann...
gateway集成hystrix全局断路器pom.xml添加依赖<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-hystrix</artifactId></dependency>在配置文件中,增加spring.cloud.gateway.default-filters:default-filters:-name:Hystrixargs:name:fallbackcmdfallbackUri:forward:/fallbackcontroller一定要注意是spring.cloud.gateway.default-filters这个配置节。如上的配...
GatewayHystrixfallback获取异常信息gatewayfallback后,需要知道请求的是哪个接口以及具体的异常信息,根据不同的请求以及异常进行不同的处理。一开始根据网上一篇博客上的做法:pom.xml:<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-gateway</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-st...
ideaconsole控制台输出乱码Idea默认配置是采用GBK,而项目工程文件采用的是UTF-8。编码不一致,导致ideaConsole控制台输出乱码。网上的解决方案,大都是直接修改Settings=>Editor=>FileEncodings下面的配置,如下图:将GlobalEncoding,也就是全局配置编码格式,跟ProjectEncoding项目编码格式配置成一样的就OK了。全局配置有时候会与项目的编码格式不一样,所以尽量不要动。但是修改ProjectEncoding,又解决不了Console...
一、简介在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件。在SpringCloud中,有分布式配置中心组件springcloudconfig,它支持配置服务放在配置服务的内存中(即本地),也支持放在远程Git仓库中。在springcloudconfig组件中,分两个角色,一是configserver,二是configclient。二、配置2.1SpringCloudConfigServer项目1pom.xml中导入ConfigServer需要的包...
一、简介在微服务的架构下,我们需要把系统的业务划分成多个单一的微服务。每个微服务都会提供接口供其他微服务调用,在Dubbo中可以通过rmi、nio等实现,SpringCloud中是通过http调用的。但有些时候,我们只希望用户通过我们的网关调用微服务,不允许用户直接请求微服务。这时我们就可以借助SpringSecurity来保障安全。二、使用步骤2.1在提供接口的微服务项目中配置SpringSecurity1首先在pom.xml引入SpringSecurity的相关配...