У меня возникла проблема при создании компонента. Я попытался устранить ошибку, набрав spring.main.allow-bean-definition-overriding=true
, но я хочу знать, почему произошла эта ошибка.
Произошло исключение. для справки см. приведенную ниже ошибку.
Description:
The bean 'configProvider', defined in class path resource
[com/fidel/fixadaptor/config/BeanConfig.class], could not be registered. A bean with that name has
already been defined in file [D:\Swapnil\Kovacap\CODE\fix-adaptor-
Ver1.1\target\classes\com\fidel\fixadaptor\config\ConfigProvider.class] and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-
definition-overriding=true
Класс конфигурации бина
@Configuration
@ComponentScan("com.fidel.fixadaptor")
public class BeanConfig {
/** The destination. */
private AdaptorDestination destination;
private ConfigProvider configProvider;
/**
* Config provider.
*
* @return the config provider
*/
@Bean
public ConfigProvider configProvider() {
if (configProvider == null) {
configProvider = new ConfigProvider();
}
return configProvider;
}
/**
* Recovery.
*
* @return the recovery
*/
@Bean
public Recovery recovery() {
return new RecoveryManager(configProvider());
}
}
Класс ConfigProvider
@Component
public class ConfigProvider {
private HashMap<String, String> configMap;
@Autowired
private FixUtils fixUtils;
/**
* @param activeProfile
* @param connectionType
* @return
*/
public HashMap<String, String> getConfig(String activeProfile, String connectionType) {
String file = fixUtils.getConfigFile(connectionType, activeProfile);
File cfgFile = new File(file);
configMap = new HashMap<String, String>();
Scanner sc = null;
try {
sc = new Scanner(cfgFile);
while (sc.hasNextLine()) {
String keyValue = sc.nextLine();
String keys[] = keyValue.split("=");
configMap.put(keys[0], keys[1]);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return configMap;
}
}
Пожалуйста, помогите мне понять, почему это происходит, для любой другой информации прокомментируйте меня. заранее спасибо