I am trying to use the Feign client. Below is my client:
import com.eprogrammerz.examples.domain.Movie; import org.springframework.cloud.netflix.feign.FeignClient; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @FeignClient(name = "movie-api") public interface MovieApi { @RequestMapping(method = RequestMethod.GET, value = "/movies/{id}") Movie getMovie(@PathVariable("id") Long id); }
I am calling from a simple service as shown below:
@Service public class MovieService { @Autowired MovieApi movieApi; public Movie findMovie(Long id){ Movie movieOfTheDay = movieApi.getMovie(id); return movieOfTheDay; } }
My spring boot application is shown below:
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; import org.springframework.cloud.netflix.feign.EnableFeignClients; @EnableFeignClients(basePackages = {"com.eprogrammerz.examples"}) @EnableCircuitBreaker @SpringBootApplication public class ClientAppApplication { public static void main(String[] args) { SpringApplication.run(ClientAppApplication.class, args); } }
build.gradle
buildscript { ext { springBootVersion = '1.4.3.RELEASE' } repositories { jcenter() mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'org.springframework.boot' jar { baseName = 'client-app' version = '0.0.1-SNAPSHOT' } sourceCompatibility = 1.8 targetCompatibility = 1.8 repositories { jcenter() mavenCentral() maven { url "https://repo.spring.io/snapshot" } maven { url "https://repo.spring.io/milestone" } } dependencies { compile('org.springframework.cloud:spring-cloud-starter-feign') // https://mvnrepository.com/artifact/com.netflix.hystrix/hystrix-core compile('org.springframework.cloud:spring-cloud-starter-hystrix') compile("org.springframework.boot:spring-boot-starter-web"){ exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging' } compileOnly('org.projectlombok:lombok') testCompile('org.springframework.boot:spring-boot-starter-test') } dependencyManagement { imports { mavenBom "org.springframework.cloud:spring-cloud-dependencies:Camden.BUILD-SNAPSHOT" mavenBom "org.springframework.boot:spring-boot-starter-parent:${springBootVersion}" } }
I get an error as shown below:
2016-12-30 13:07:16.894 INFO 6748 --- [nio-8082-exec-1] osweb.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 39 ms 2016-12-30 13:07:16.939 INFO 6748 --- [nio-8082-exec-1] ceecontrollers.RequestController : Calling findMovie(1203) 2016-12-30 13:07:17.240 INFO 6748 --- [rix-movie-api-1] scaAnnotationConfigApplicationContext : Refreshing org.spring framework.context.annotation.AnnotationConfigApplicationContext@ 547496c2: startup date [Fri Dec 30 13:07:17 EST 2016]; parent: org.springframework.boot .context.embedded.AnnotationConfigEmbeddedWebApplicationContext@ 542e560f 2016-12-30 13:07:17.318 INFO 6748 --- [rix-movie-api-1] faAutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring 2016-12-30 13:07:17.619 INFO 6748 --- [rix-movie-api-1] c.netflix.config.ChainedDynamicProperty : Flipping property: movie-api.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647 2016-12-30 13:07:17.670 INFO 6748 --- [rix-movie-api-1] cnuconcurrent.ShutdownEnabledTimer : Shutdown hook installed for: NFLoadBalancer-PingTimer-movie-api 2016-12-30 13:07:17.727 INFO 6748 --- [rix-movie-api-1] c.netflix.loadbalancer.BaseLoadBalancer : Client:movie-api instantiated a LoadBalancer:DynamicServerListLoadBalancer:{NFLoadBalancer:name=movie-api,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:null 2016-12-30 13:07:17.739 INFO 6748 --- [rix-movie-api-1] cnlDynamicServerListLoadBalancer : Using serverListUpdater PollingServerListUpdater 2016-12-30 13:07:17.746 INFO 6748 --- [rix-movie-api-1] cnlDynamicServerListLoadBalancer : DynamicServerListLoadBalancer for client movie-api initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=movie-api,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList: com.netflix.loadbalancer.ConfigurationBasedServerList@45bcfd5 2016-12-30 13:07:18.191 ERROR 6748 --- [nio-8082-exec-1] oaccC[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is com.netflix.hystrix.exception.HystrixRuntimeException: MovieApi
I tried a different way. But could not find a solution. I could not find any information about this on Spring Cloud Netflix . I also could not find any information in the thread of the discussion thread .
What am I missing here? TIA.
Additional information:
application.yml for microservice movie-api:
server: port: 8090 logging: config: classpath:log4j2.yml spring: application: name: movie-api
Spring boot application for movie-api module:
@SpringBootApplication public class MovieApiApplication { public static void main(String[] args) { SpringApplication.run(MovieApiApplication.class, args); } }
And the controller as below:
@RestController @Slf4j public class MovieController { @Autowired private MovieRepository movieRepository; @RequestMapping("/movies/{id}") public ResponseEntity<Movie> getBook(@PathVariable("id") Long id){ log.trace("getBook({})",id); Optional<Movie> movie = Optional.of(movieRepository.findOneById(id)); if(movie.isPresent()) return new ResponseEntity(movie.get(), HttpStatus.OK); return new ResponseEntity<Movie>(HttpStatus.NOT_FOUND); } }