1

I already tried solutions on this and this but no success so maybe I'm missing something else

here is my architecture

I have a ressource micro-service protected by Oauth2 which is implementing my business logic and a client micro-service with a thymleaf template that is consuming this ressource. Using Oauth2RestTemplate is fine now i m trying to use feign.

first here is my ressource project resume

Application.yml

spring.application.name: COMPONENTS

server:
  port: 0


  
eureka.client.service-url.defaultZone: xxxxxxxxxxxxxxxxxxxxxxxx

security.oauth2.resource.token-info-uri: xxxxxxxxxxxxxxxxxxxxxx
security.oauth2.client.client-id: xxxxxxxxxxxxxx
security.oauth2.client.client-secret: xxxxxxxxxxxxx

spring.jackson.date-format: com.fasterxml.jackson.databind.util.ISO8601DateFormat


spring:
  datasource:
    url: jdbc:mariadb://localhost:3306/pos_auth?createDatabaseIfNotExist=true
    username: root
    password: xxxxxxxx
    driver-class-name: org.mariadb.jdbc.Driver

And a simple Controller

@Controller
@RequestMapping(ApplicationController.API)
public class ApplicationController {
    
    public static final String API = "applications";
    
    @Autowired
    private ComponentsService componentsService;
    
    @GetMapping
    public ResponseEntity<List<Apps>> getApplicationsList() {
        return new ResponseEntity<List<Apps>>(componentsService.getAllApps(), HttpStatus.OK);
    }

    
}

Now here is My client important part of Feign client implementation

the main class

@SpringBootApplication
@EnableOAuth2Sso
@EnableEurekaClient
@EnableDiscoveryClient
@EnableWebSecurity
public class ClientApplication extends WebSecurityConfigurerAdapter{


    public static void main(String[] args) {
        SpringApplication.run(ClientApplication.class, args);
    }
    
    
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http
                    .logout()
                    .logoutSuccessUrl("http://localhost:9999/uaa/exit");
            http.authorizeRequests().antMatchers("/graphics/**").permitAll().
                    and().authorizeRequests().anyRequest().authenticated();
        }
   

    @Bean
    @LoadBalanced
    OAuth2RestTemplate oauth2RestTemplate(OAuth2ClientContext oauth2ClientContext, OAuth2ProtectedResourceDetails details) {
        return new OAuth2RestTemplate(details, oauth2ClientContext);
    }

    @Profile("!cloud")
    @Bean
    RequestDumperFilter requestDumperFilter() {
        return new RequestDumperFilter();
    }

}

A feign configuration

@Configuration
@EnableFeignClients
@ImportAutoConfiguration({RibbonAutoConfiguration.class, FeignRibbonClientAutoConfiguration.class, FeignAutoConfiguration.class})
public class FeignConfig {

}

My desired behaviour in the client controller when index is called

@Controller
public class MessageController {

    @Autowired
    OAuth2RestTemplate restTemplate;

    
    @Autowired
    private AppClientFeign appClientFeign;


    @RequestMapping("/")
    String home(Model model) {
        model.addAttribute("applications", appClientFeign.getApps());
        System.out.println(appClientFeign.getApps());
        return "index";
    }

  
}

finally my feign client

@FeignClient("COMPONENTS")
public interface AppClientFeign {
    @RequestMapping(method = RequestMethod.GET, value = "/applications")
    List<App> getApps();
}

while running the client I m getting the following exception

Field appClientFeign in demo.MessageController required a bean of type 'org.springframework.cloud.netflix.feign.FeignContext' that could not be found.

  • Bean method 'feignContext' not loaded because @ConditionalOnClass did not find required class 'feign.Feign'
Community
  • 1
  • 1

2 Answers2

0

the explanation: knowing that spring cloud have Feign by default not adding the feign starter dependency will not trigger any compilation time issue (as using javax jpa that should be injected by a starter project Data JPA) in my case I forgot to add the starter to the project pom, spring search for an implemntation or a comfiguration that he can't found.

the solution adding the starter feign dependency

<dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
0

For Spring Boot version above 2.0.0.M4 use

         <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
         </dependency>
abhinav kumar
  • 1,487
  • 1
  • 12
  • 20