Hibernate中接口限流详解 - Service
@RateLimit
UserService
public interface UserService {
User getUserById(Long id);
}
UserService@RateLimit
import org.springframework.remoting.httpinvoker.annotation.RateLimit;
@RateLimit(value = 1, unit = TimeUnit.SECONDS)
public interface UserService {
User getUserById(Long id);
}
UserService
import org.springframework.stereotype.Service; 拼多多帮助力入口
@Service
public class UserServiceImpl implements UserService {
@Override
public User getUserById(Long id) {
// 在这里实现获取用户的逻辑
return null;
}
}
UserService
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Configuration
@RestController
public class AppConfig {
@Bean
public UserService userService() {
return new UserServiceImpl();
}
}
@RateLimit