简体   繁体   中英

“A bean with that name has already been defined” error coming in spring boot multi module project

I am working with one spring boot multi module maven project, here i am getting below exception, every time when i run application it fails for different different files.

 The bean 'evServiceCpeRepository' could not be registered. A bean with that name has already been defined

this project has three module sbill, amr and executable,

this all classes i have in sbill module... amr module is empty it has just one controller and in amr module pom file i have added dependency for sbill module because amr module can access classes of sbill.

executable module just contain spring boot main class, apart from that no any classes this module is executable module.

 @SpringBootApplication
@ComponentScan(basePackages = { "com"})
@EntityScan(basePackages = { "com"})
 @EnableJpaRepositories(basePackages = { "com"})
 public class MainClass {public static void main(String[] args) {
 SpringApplication.run(MainClass.class, args);
 }}

pom of executable module

<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.sbill</groupId>
      <artifactId>sbill-wrapper</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      </parent>
       <packaging>war</packaging>
      <artifactId>executable</artifactId>

<dependencies>
  <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
      <dependency>
       <groupId>com.sbill</groupId>
       <artifactId>sbill</artifactId>
         <version>0.0.1-SNAPSHOT</version>
       </dependency> 

     <dependency>
    <groupId>com.sbill</groupId>
    <artifactId>amr</artifactId>
      <version>0.0.1-SNAPSHOT</version>
    </dependency>

    </dependencies> 


<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>

        <!-- Adding  plugin of mavan resource to copy dist folder for  war -->
        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>3.1.0</version>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>


           <outputDirectory>${project.build.directory}/classes/static/</outputDirectory>
                        <resources>
                            <resource>
                                <directory>../web/dist</directory>
                            </resource>         
                        </resources>            
                    </configuration>            
                 </execution>           
                </executions>
            </plugin>
          </plugins>       
       </build>  
      </project>       

I am able to resolve this issue myself... issue was related to @EnableJpaRepositories(basePackages = { "com"}) annotation. this annotation i have put in Mainclass.java file and this annotation was already there in one configuration file of module sbill.

so two times spring was trying to create beans that's why it was failing. i removed that annotation from another configuration file and its works perfectly fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM