productClient不能autowire

来源:6-3 Config Client

weixin_慕尼黑2067412

2019-08-07

启动报错

Description:

Field productClient in com.luaj.order.service.impl.OrderServiceImpl required a bean of type 'com.luaj.product.client.ProductClient' that could not be found.


Action:

Consider defining a bean of type 'com.luaj.product.client.ProductClient' in your configuration.

图片描述
product-client端代码及POM文件:

import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

@FeignClient
public interface ProductClient {
    @GetMapping("/msg")
    String productMsg();
    @PostMapping("/product/listForOrder")
    public List<ProductInfoOutput> list(@RequestBody List<String> productList);
    @PostMapping("/product/decreaseStock")
    public  void decreaseStock(@RequestBody List<DecreaseStockInput> decreaseStockInputList);
}

pom文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.luaj</groupId>
            <artifactId>product-common</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-netflix-core</artifactId>
        </dependency>

    </dependencies>

    <parent>
        <groupId>com.luaj</groupId>
        <artifactId>product</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <artifactId>product-client</artifactId>

    
</project>

order-server POM文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.luaj</groupId>
        <artifactId>order</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <artifactId>order-server</artifactId>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-client</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </depelndency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
        </dependency>
        <dependency>
            <groupId>com.luaj</groupId>
            <artifactId>order-common</artifactId>
        </dependency>
        <dependency>
            <groupId>com.luaj</groupId>
            <artifactId>product-client</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork>
                </configuration>
            </plugin>
        </plugins>
    </build>
    
</project>

我的模块有问题吗

写回答

2回答

晨猫

2019-08-09


@EnableFeignClients(basePackageClasses = {
       XxxClient.class})
@SpringBootApplication
public class XxxApplication {

   public static void main(String[] args) {
       SpringApplication.run(MicroVideoApplication.class, args);
   }

}

0
1
weixin_慕尼黑2067412
非常感谢!
2019-08-09
共1条回复

廖师兄

2019-08-08

为什么都没引入feign依赖?你对比课程源码

0
0

SpringCloud Finchley(M2+RELEASE+SR2)微服务实战

SpringCloud组件实现微服务,【已升级Finchley.Release】

5673 学习 · 2489 问题

查看课程