【springboot】 静态(static)方法中调用接口(Service层)

@Component
public class JwtUtil {
    /**
     * 静态方法调用非静态接口层(Service层)
     */
    public static JwtUtil jwtUtil; //声明对象

    @PostConstruct //初始化
    public void init() {
        jwtUtil = this;
        jwtUtil.userService = this.userService;
    }

    @Autowired //注入
            UserService userService;


public static boolean checkSign(String token) {
...
 String username= jwtUtil.userService.getUsernameById(userId);
...
}

你可能感兴趣的:(后端,java,aop)