Java &引用;已经定义了一个具有该名称的bean;spring boot多模块项目中出现错误
我正在使用一个SpringBoot多模块maven项目,在这里我得到以下异常,每次我运行应用程序时,它都会因不同的文件而失败Java &引用;已经定义了一个具有该名称的bean;spring boot多模块项目中出现错误,java,maven,spring-boot,Java,Maven,Spring Boot,我正在使用一个SpringBoot多模块maven项目,在这里我得到以下异常,每次我运行应用程序时,它都会因不同的文件而失败 The bean 'evServiceCpeRepository' could not be registered. A bean with that name has already been defined 该项目有三个模块sbill、amr和可执行文件 这是我在sbill模块中的所有类。。。amr模块是空的,它只有一个控制器,在amr模块pom文件中,我为sbi
The bean 'evServiceCpeRepository' could not be registered. A bean with that name has already been defined
该项目有三个模块sbill、amr和可执行文件
这是我在sbill模块中的所有类。。。amr模块是空的,它只有一个控制器,在amr模块pom文件中,我为sbill模块添加了依赖项,因为amr模块可以访问sbill的类
可执行模块只包含SpringBoot主类,除此之外,该模块没有任何类是可执行模块
@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
<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>
4.0.0
com.sbill
sbill包装器
0.0.1-快照
战争
可执行
org.springframework.boot
SpringBootStarterWeb
com.sbill
斯比尔
0.0.1-快照
com.sbill
amr
0.0.1-快照
org.springframework.boot
springbootmaven插件
maven资源插件
3.1.0
复制资源
验证
复制资源
${project.build.directory}/classes/static/
../web/dist
我可以自己解决这个问题。。。
问题与@EnableJpaRepositories(basePackages={“com”})
注释有关。这个注释我已经放在Mainclass.java文件中,这个注释已经存在于模块sbill的一个配置文件中
因此,spring曾两次尝试创建bean,这就是它失败的原因。
我从另一个配置文件中删除了该注释,它工作得非常好。我自己能够解决这个问题。。。 问题与
@EnableJpaRepositories(basePackages={“com”})
注释有关。这个注释我已经放在Mainclass.java文件中,这个注释已经存在于模块sbill的一个配置文件中
因此,spring曾两次尝试创建bean,这就是它失败的原因。
我从另一个配置文件中删除了该注释,它工作得非常好。您使用的是哪个IDE。请检查作为依赖项添加的项目中是否显示任何错误。如果是,请先解决这些问题,然后尝试重建项目。@AkshayJoshi我正在使用eclipse ide,但我正在从命令提示符下构建应用程序,然后也会出现相同的错误。。属性文件中的应用程序中没有任何错误。如果我提到“spring.main.allow bean definition overriding=true”,则应用程序工作正常,但这只是解决方法。请尝试在应用程序中添加spring.main.allow bean definition overriding=true。属性文件中使用哪个IDE。请检查作为依赖项添加的项目中是否显示任何错误。如果是,请先解决这些问题,然后尝试重建项目。@AkshayJoshi我正在使用eclipse ide,但我正在从命令提示符下构建应用程序,然后也会出现相同的错误。。属性文件中的应用程序中没有任何错误。如果我提到“spring.main.allow bean definition overriding=true”,则应用程序工作正常,但这只是解决方法。请尝试在application.properties文件中添加spring.main.allow bean definition overriding=true