<bdo id='oa8Kp'></bdo><ul id='oa8Kp'></ul>

    <small id='oa8Kp'></small><noframes id='oa8Kp'>

  • <i id='oa8Kp'><tr id='oa8Kp'><dt id='oa8Kp'><q id='oa8Kp'><span id='oa8Kp'><b id='oa8Kp'><form id='oa8Kp'><ins id='oa8Kp'></ins><ul id='oa8Kp'></ul><sub id='oa8Kp'></sub></form><legend id='oa8Kp'></legend><bdo id='oa8Kp'><pre id='oa8Kp'><center id='oa8Kp'></center></pre></bdo></b><th id='oa8Kp'></th></span></q></dt></tr></i><div id='oa8Kp'><tfoot id='oa8Kp'></tfoot><dl id='oa8Kp'><fieldset id='oa8Kp'></fieldset></dl></div>
      <tfoot id='oa8Kp'></tfoot>

      1. <legend id='oa8Kp'><style id='oa8Kp'><dir id='oa8Kp'><q id='oa8Kp'></q></dir></style></legend>
      2. SpringBoot - BeanDefinitionOverrideException:无效的bean定义

        SpringBoot - BeanDefinitionOverrideException: Invalid bean definition(SpringBoot - BeanDefinitionOverrideException:无效的bean定义)

              <legend id='SSZtl'><style id='SSZtl'><dir id='SSZtl'><q id='SSZtl'></q></dir></style></legend>
            • <small id='SSZtl'></small><noframes id='SSZtl'>

                <bdo id='SSZtl'></bdo><ul id='SSZtl'></ul>

                  <tfoot id='SSZtl'></tfoot>
                1. <i id='SSZtl'><tr id='SSZtl'><dt id='SSZtl'><q id='SSZtl'><span id='SSZtl'><b id='SSZtl'><form id='SSZtl'><ins id='SSZtl'></ins><ul id='SSZtl'></ul><sub id='SSZtl'></sub></form><legend id='SSZtl'></legend><bdo id='SSZtl'><pre id='SSZtl'><center id='SSZtl'></center></pre></bdo></b><th id='SSZtl'></th></span></q></dt></tr></i><div id='SSZtl'><tfoot id='SSZtl'></tfoot><dl id='SSZtl'><fieldset id='SSZtl'></fieldset></dl></div>
                    <tbody id='SSZtl'></tbody>
                  本文介绍了SpringBoot - BeanDefinitionOverrideException:无效的bean定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试使用 Spring Boot 在本地设置 DynamoDB.最初,我使设置正常工作,并且能够通过存储库写入/保存到 DynamoDB.从那时起,我添加了更多类来构建我的应用程序.现在,当我尝试启动我的应用程序时,出现以下异常:

                  I am trying to setup DynamoDB locally with Spring Boot. Initially I got the setup working and was able to write/save to DynamoDB via a repository. From that point I added more classes to build my application. Now when I try to start my application, I get the following exception:

                  org.springframework.beans.factory.support.BeanDefinitionOverrideException:无效的 bean 定义,名称为 'agentRepository' 在 null 中定义:无法注册 bean 定义 [根 bean:类 [org.socialsignin.spring.data.dynamodb.repository.support.DynamoDBRepositoryFactoryBean];范围=;摘要=假;懒惰初始化=假;自动线模式=0;依赖检查=0;自动接线候选=真;主要=假;工厂BeanName=空;工厂方法名=空;初始化方法名=空;bean 'agentRepository' 的 destroyMethodName=null]:已经有 [根 bean:类 [org.socialsignin.spring.data.dynamodb.repository.support.DynamoDBRepositoryFactoryBean];范围=;摘要=假;懒惰初始化=假;自动线模式=0;依赖检查=0;自动接线候选=真;主要=假;工厂BeanName=空;工厂方法名=空;初始化方法名=空;destroyMethodName=null] 绑定.

                  我已经广泛搜索了 SO 和互联网,但没有任何有用的解决方案.错误消息也具有误导性.

                  I have searched SO and internet extensively but there were no any useful solution to this. The error message is misleading as well.

                  我的项目具有以下层次结构

                  My project is of the following hierarchy

                  ai.test.as
                    - as
                        - agent
                            - business
                            - intent
                            - exception
                            - Agent.java
                            - AgentDTO.java
                            - AgentRespository.java
                            - AgentController.java
                            - AgentService.java
                            - AgentServiceImpl.java
                    - config
                       - DynamoDBConfig.java
                  

                  DynamoDBConfig.java

                  DynamoDBConfig.java

                  package ai.test.as.config;
                  
                  import ai.test.as.agent.AgentRepository;
                  import ai.test.as.agent.intent.template.TemplateRepository;
                  import com.amazonaws.auth.AWSCredentials;
                  import com.amazonaws.auth.BasicAWSCredentials;
                  import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
                  import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;
                  import org.socialsignin.spring.data.dynamodb.repository.config.EnableDynamoDBRepositories;
                  import org.springframework.beans.factory.annotation.Value;
                  import org.springframework.context.annotation.Bean;
                  import org.springframework.context.annotation.Configuration;
                  
                  @Configuration
                  @EnableDynamoDBRepositories(basePackageClasses = {AgentRepository.class})
                  public class DynamoDBConfig
                  {
                      @Value("${aws.dynamodb.endpoint}")
                      private String dynamoDBEndpoint;
                  
                      @Value("${aws.auth.accesskey}")
                      private String awsAccessKey;
                  
                      @Value("${aws.auth.secretkey}")
                      private String awsSecretKey;
                  
                      @Bean
                      public AmazonDynamoDB amazonDynamoDB()
                      {
                          AmazonDynamoDB dynamoDB = new AmazonDynamoDBClient(getAwsCredentials());
                          dynamoDB.setEndpoint(dynamoDBEndpoint);
                  
                          return dynamoDB;
                      }
                  
                      @Bean
                      public AWSCredentials getAwsCredentials()
                      {
                          return new BasicAWSCredentials(awsAccessKey, awsSecretKey);
                      }
                  }
                  

                  AgentRepository.java

                  AgentRepository.java

                  package ai.test.as.agent;
                  
                  import ai.test.as.agent.Agent;
                  import org.socialsignin.spring.data.dynamodb.repository.EnableScan;
                  import org.springframework.data.repository.CrudRepository;
                  
                  @EnableScan
                  public interface AgentRepository extends CrudRepository<Agent, String>
                  {
                  }
                  

                  AgentController.java(使用 AgentRepository 的地方)

                  AgentController.java (Where AgentRepository is used)

                  @RestController
                  @RequestMapping(value = "/v1/agents")
                  public class AgentController
                  {
                      @Autowired
                      private AgentRepository agentRepository;
                  
                      @RequestMapping(value = "/test", method = RequestMethod.POST)
                      public void test()
                      {
                          Agent agent = new Agent();
                          agent.setAgentNumber("123456");
                          agent.setId(1);
                  
                          agentRepository.save(agent);
                      }
                  }
                  

                  Spring 建议如下:<代码>>在 null 中定义的 bean 'agentRepository' 无法注册.已在 null 中定义了具有该名称的 bean,并且已禁用覆盖.

                  Spring suggests the following: > The bean 'agentRepository', defined in null, could not be registered. A bean with that name has already been defined in null and overriding is disabled.

                  null 在这里是什么意思?是因为我的应用程序配置有问题吗?还有怎么可能已经注册了?

                  What does null mean here? Is it because something wrong in my application config? Also how is it possible that it is already registered?

                  请给我一些指示,因为我对接下来的步骤感到很困惑.

                  Please give me some pointers because I so confused about my next steps.

                  推荐答案

                  从 Spring Boot 2.1 开始必须启用 Bean 覆盖,

                  Bean overriding has to be enabled since Spring Boot 2.1,

                  https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.1-Release-Notes

                  Bean 覆盖

                  默认情况下禁用 Bean 覆盖以防止意外覆盖 bean.如果您依赖覆盖,则需要将 spring.main.allow-bean-definition-overriding 设置为 true.

                  Bean overriding has been disabled by default to prevent a bean being accidentally overridden. If you are relying on overriding, you will need to set spring.main.allow-bean-definition-overriding to true.

                  设置

                  spring.main.allow-bean-definition-overriding=true
                  

                  或yml,

                  spring:
                     main:
                       allow-bean-definition-overriding: true
                  

                  再次启用覆盖.

                  编辑,

                  Bean Overriding 是基于 bean 的名称而不是它的类型.例如

                  Bean Overriding is based of the name of the bean not its type. e.g.

                  @Bean
                  public ClassA class(){
                     return new ClassA();
                  }
                  
                  @Bean
                  public ClassB class(){
                     return new ClassB();
                  }
                  

                  会在>中造成这个错误2.1,默认情况下bean名称取自方法名称.重命名方法或将 name 属性添加到 Bean 注释将是有效的修复方法.

                  Will cause this error in > 2.1, by default bean names are taken from the method name. Renaming the method or adding the name attribute to the Bean annotation will be a valid fix.

                  这篇关于SpringBoot - BeanDefinitionOverrideException:无效的bean定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Lucene Porter Stemmer not public(Lucene Porter Stemmer 未公开)
                  How to index pdf, ppt, xl files in lucene (java based or python or php any of these is fine)?(如何在 lucene 中索引 pdf、ppt、xl 文件(基于 java 或 python 或 php 中的任何一个都可以)?)
                  KeywordAnalyzer and LowerCaseFilter/LowerCaseTokenizer(KeywordAnalyzer 和 LowerCaseFilter/LowerCaseTokenizer)
                  How to search between dates (Hibernate Search)?(如何在日期之间搜索(休眠搜索)?)
                  How to get positions from a document term vector in Lucene?(如何从 Lucene 中的文档术语向量中获取位置?)
                  Java Lucene 4.5 how to search by case insensitive(Java Lucene 4.5如何按不区分大小写进行搜索)

                  <small id='8mXN1'></small><noframes id='8mXN1'>

                  • <bdo id='8mXN1'></bdo><ul id='8mXN1'></ul>

                      1. <i id='8mXN1'><tr id='8mXN1'><dt id='8mXN1'><q id='8mXN1'><span id='8mXN1'><b id='8mXN1'><form id='8mXN1'><ins id='8mXN1'></ins><ul id='8mXN1'></ul><sub id='8mXN1'></sub></form><legend id='8mXN1'></legend><bdo id='8mXN1'><pre id='8mXN1'><center id='8mXN1'></center></pre></bdo></b><th id='8mXN1'></th></span></q></dt></tr></i><div id='8mXN1'><tfoot id='8mXN1'></tfoot><dl id='8mXN1'><fieldset id='8mXN1'></fieldset></dl></div>

                            <tbody id='8mXN1'></tbody>

                            <legend id='8mXN1'><style id='8mXN1'><dir id='8mXN1'><q id='8mXN1'></q></dir></style></legend><tfoot id='8mXN1'></tfoot>