Code Monkey home page Code Monkey logo

Comments (4)

shiyujun avatar shiyujun commented on May 14, 2024

我下载到源码后 必须在rateLimiter这个变量上加@Autowired这个注解才能注册进去值 否则 打印出来rateLimiter为空
是我的环境的问题?还是框架有问题呢?

有没有增加启动注解@EnableSyjRateLimit呢,如果增加了启动注解的话会在EnableSyjRateLimitConfiguration这个类里面自动装配的

from syj-ratelimit.

mrsWangxing avatar mrsWangxing commented on May 14, 2024

@EnableSyjRateLimit 这个注解加了
EnableSyjRateLimitConfiguration这个类确实会在spring容器中放入 一个RateLimiter类型的对象
但是 在 TokenBucketAlgorithmImpl 这个类里面 的 rateLimiter 这个属性 没有@Autowired 在consume方法中用的时候 会报空指针异常
假如不加这个注解 @Autowired ;是什么原理把rateLimiter 注入到TokenBucketAlgorithmImpl 这个类里面的呢

from syj-ratelimit.

shiyujun avatar shiyujun commented on May 14, 2024

@EnableSyjRateLimit 这个注解加了
EnableSyjRateLimitConfiguration这个类确实会在spring容器中放入 一个RateLimiter类型的对象
但是 在 TokenBucketAlgorithmImpl 这个类里面 的 rateLimiter 这个属性 没有@Autowired 在consume方法中用的时候 会报空指针异常
假如不加这个注解 @Autowired ;是什么原理把rateLimiter 注入到TokenBucketAlgorithmImpl 这个类里面的呢

这个对象注入主要是使用了Lombok插件的@requiredargsconstructor,这个注解为类提供了一个包含带有@nonnull注解变量的构造方法,Spring在执行时就会自动把这些变量注入进去。你的情况可能是因为本地开发工具没有集成Lombok的原因。可以选择使用maven**仓库的依赖或者开发工具增加Lombok集成环境

from syj-ratelimit.

mrsWangxing avatar mrsWangxing commented on May 14, 2024

嗯 应该是这个原因

from syj-ratelimit.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.