marcosbarbero / spring-cloud-zuul-ratelimit

Rate limit auto-configure for Spring Cloud Netflix Zuul
https://blog.marcosbarbero.com/spring-cloud-netflix-zuul-rate-limit/
Apache License 2.0
1.14k stars 389 forks source link

APPLICATION FAILED TO START #39

Closed fuhongtao closed 6 years ago

fuhongtao commented 6 years ago

use version 1.3.4.RELEASE add property zuul.ratelimit.repository Parameter 0 of method rateLimiterPreFilter in com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.RateLimitAutoConfiguration required a bean of type 'com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.RateLimiter' that could not be found.

marcosbarbero commented 6 years ago

What was the value you added to the property?

fuhongtao commented 6 years ago

i try zuul.ratelimit.repository=IN_MEMORY and zuul.ratelimit.repository=REDIS . all two make mistakes

marcosbarbero commented 6 years ago

Do you have a sample project that I can check?

fuhongtao commented 6 years ago

I'll email you

marcosbarbero commented 6 years ago

Ok, thank you

fuhongtao commented 6 years ago

Thank you for your support. For some reason, I may not send the item to you by mail. Please paste some files of my project for reference.

org.springframework.boot spring-boot-starter-parent 1.5.6.RELEASE
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <spring-cloud.version>Dalston.SR4</spring-cloud.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-eureka</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-zuul</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-cache</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-redis</artifactId>
    </dependency>
    <dependency>
        <groupId>com.maihaoche</groupId>
        <artifactId>spring-boot-starter-rocketmq</artifactId>
        <version>0.0.4</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-oauth2</artifactId>
    </dependency>
    <dependency>
        <groupId>com.marcosbarbero.cloud</groupId>
        <artifactId>spring-cloud-zuul-ratelimit</artifactId>
        <version>1.3.4.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

zuul

zuul.routes.api.stripPrefix=false /api/user/list -> /api/user/list

zuul.ribbon.eager-load.enabled= true

zuul.sensitiveHeaders= zuul.add-host-headers=true

zuul.routes.local.path=/local/** zuul.routes.local.url=forward:/local

zuul.ratelimit.enabled=true

zuul.ratelimit.repository=IN_MEMORY

zuul.ratelimit.policies.local.limit=3 zuul.ratelimit.policies.local.refresh-interval=60 zuul.ratelimit.policies.local.type=origin zuul.ratelimit.policies.yd-admin.limit=30 zuul.ratelimit.policies.yd-admin.refresh-interval=60 zuul.ratelimit.policies.yd-admin.type=origin

fuhongtao commented 6 years ago

When I add the following code, everything is OK

public static void main(String[] args) {
    // RateLimitAutoConfiguration a;
    SpringApplication.run(YdGatewayApplication.class, args);
}
  @Bean("rateLimiterRedisTemplate")
  public StringRedisTemplate redisTemplate(final RedisConnectionFactory connectionFactory) {
      return new StringRedisTemplate(connectionFactory);
  }

  @Bean
  public RateLimiter redisRateLimiter(@Qualifier("rateLimiterRedisTemplate") final RedisTemplate redisTemplate) {
      return new RedisRateLimiter(redisTemplate);
  }
marcosbarbero commented 6 years ago

I’ll play with your configuration and let you know once I have a solution

marcosbarbero commented 6 years ago

@fuhongtao can you take a look at this sample?

fuhongtao commented 6 years ago

i try the sample,it's not work.

marcosbarbero commented 6 years ago

I'll double check it