springboot 启动时设置排除的类文件
·
一、项目执行过程中经常会遇到jar包中的某些配置无法满足业务需求,需要重新覆盖的场景
package cn.com.vpp;
import cn.com.foundation.data.conf.MybatisPlusConfiguration;
import cn.com.gb.base.api.aspect.TokenAspect;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.FilterType;
import org.springframework.scheduling.annotation.EnableScheduling;
@MapperScan({"cn.com.**.mapper"})
@SpringBootApplication
@ComponentScan(basePackages = "cn.com.**", excludeFilters = {
@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,
classes = {
cn.com.foundation.data.conf.MybatisPlusConfiguration.class,
TokenAspect.class
})
})
@EnableScheduling
@EnableFeignClients({"cn.com.vpp.**", "cn.com.iot.**"})
@EnableCaching
@EnableAspectJAutoProxy
public class VppApplication {
public static void main(String[] args) {
SpringApplication.run(VppApplication.class, args);
}
}
二、排除后重新编写覆盖的配置等
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
package cn.com.vpp.aspect;
import cn.com.gb.base.api.service.TokenService;
import cn.com.gb.base.api.utils.BaseContextUtil;
import java.util.Map;
import java.util.Objects;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
@Order(1)
@Aspect
@Component
public class TokenAspectNew {
private static final Logger log = LoggerFactory.getLogger(TokenAspectNew.class);
@Autowired
private TokenService tokenService;
public TokenAspectNew() {
}
@Pointcut("execution(* cn.togeek.*..*Controller.*(..))")
public void tokenPointCut() {
}
@Before("tokenPointCut()")
public void tokenBefore() {
BaseContextUtil.remove();
Map<String, Object> tokenMessage = this.tokenService.getToken();
BaseContextUtil.set("userId", tokenMessage.get("userId") == null ? "" : tokenMessage.get("userId").toString());
BaseContextUtil.set("tenantId", tokenMessage.get("tenantId") == null ? "" : tokenMessage.get("tenantId").toString());
BaseContextUtil.set("userName", tokenMessage.get("userName") == null ? "" : tokenMessage.get("userName").toString());
BaseContextUtil.set("orgId", tokenMessage.get("orgId") == null ? "" : tokenMessage.get("orgId").toString());
if (Objects.nonNull(tokenMessage.get("gridIds"))) {
BaseContextUtil.set("gridIds", tokenMessage.get("gridIds").toString());
}
}
}
更多推荐


所有评论(0)