如果spring容器中存在某个类型的bean有多个,在根据类型获取bean的时候就会报expected single matching bean but found(期望匹配一个bean,但是发现多个)的错误,请看下面的实例。

  示例1:

  pom.xml

<?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>

    <groupId>com.edu.spring</groupId>
    <artifactId>spring</artifactId>
    <version>1.0.0</version>

    <name>spring</name>
    <!-- FIXME change it to the project's website -->
    <url>http://www.example.com</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
    
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.3.2.RELEASE</version>
        </dependency>
    </dependencies>

</project>
View Code

相关文章:

  • 2021-10-07
  • 2022-12-23
  • 2021-09-20
  • 2022-12-23
  • 2022-12-23
  • 2021-12-21
  • 2021-06-21
  • 2021-09-27
猜你喜欢
  • 2021-05-29
  • 2021-07-15
  • 2022-12-23
  • 2022-02-03
  • 2022-12-23
  • 2021-09-23
  • 2021-06-26
相关资源
相似解决方案