Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

Exception - NoUniqueBeanException

Bom dia, estou com um este erro no projeto! Segue stacktrace abaixo

language: pt

Encoding: ISO-8859-1

Author: Vinicius Rocha

Version: 1.0

Funcionalidade: PDT821HipercardAmexRelatorioIncomingInclearContestacoes

-Narrativa Necessario ter transacoes aprovadas no arquivo inclear Ter arquivo de inclear gerado Verificar se nomeclatura do arquivo esta de acordo com a bandeira Qualquer tipo de duvida sobre a validacao do arquivo consultar manual da bandeira

-Fora do Escopo Validacao de Transacoes Ecommerce para bandeiras diferentes de Hipercard, Amex, Mastercard, Visa, Elo

10:04:47.032 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
10:04:47.049 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
10:04:47.086 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [br.com.cielo.automacao.steps.star.relatorios.bandeiras.ControleDeReapresentacoesStep] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper]
10:04:47.123 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [br.com.cielo.automacao.steps.star.relatorios.bandeiras.ControleDeReapresentacoesStep]: class path resource [br/com/cielo/automacao/steps/star/relatorios/bandeiras/ControleDeReapresentacoesStep-context.xml] does not exist
10:04:47.125 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [br.com.cielo.automacao.steps.star.relatorios.bandeiras.ControleDeReapresentacoesStep]: class path resource [br/com/cielo/automacao/steps/star/relatorios/bandeiras/ControleDeReapresentacoesStepContext.groovy] does not exist
10:04:47.127 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [br.com.cielo.automacao.steps.star.relatorios.bandeiras.ControleDeReapresentacoesStep]: no resource found for suffixes {-context.xml, Context.groovy}.
10:04:47.187 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [br.com.cielo.automacao.steps.star.relatorios.bandeiras.ControleDeReapresentacoesStep]
10:04:47.216 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - @TestExecutionListeners is not present for class [br.com.cielo.automacao.steps.star.relatorios.bandeiras.ControleDeReapresentacoesStep]: using defaults.
10:04:47.229 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]
10:04:47.263 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Could not instantiate TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener]. Specify custom listener classes or make the default listener classes (and their required dependencies) available. Offending class: [javax/servlet/ServletContext]
10:04:47.263 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@560348e6, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@1df8b5b8, org.springframework.test.context.support.DirtiesContextTestExecutionListener@23202fce, org.springframework.test.context.transaction.TransactionalTestExecutionListener@7b993c65, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@37911f88, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@6f1c29b7, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@4d6025c5, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@7f284218, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@407a7f2a, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@4ea5b703, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@2a7ed1f]
10:04:47.375 [main] DEBUG org.springframework.core.env.StandardEnvironment - Adding [systemProperties] PropertySource with lowest search precedence
10:04:47.376 [main] DEBUG org.springframework.core.env.StandardEnvironment - Adding [systemEnvironment] PropertySource with lowest search precedence
10:04:47.377 [main] DEBUG org.springframework.core.env.StandardEnvironment - Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
10:04:47.379 [main] DEBUG org.springframework.core.env.MutablePropertySources - Adding [inline] PropertySource with highest search precedence
10:04:47.385 [main] DEBUG org.springframework.test.context.support.TestPropertySourceUtils - Adding inlined properties to environment: {spring.jmx.enabled=false, org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true, server.port=-1}
10:04:47.386 [main] DEBUG org.springframework.core.env.StandardEnvironment - Adding [Inlined Test Properties] PropertySource with highest search precedence
.   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.5.1.RELEASE)

2017-06-14 10:04:47.954  INFO 10216 --- [           main] .a.s.s.r.b.ControleDeReapresentacoesStep : Starting ControleDeReapresentacoesStep on LP0348 with PID 10216 (C:\dev\inmetrics\workspace_branchs\developer\in_automation\target\classes started by Inmetrics in C:\dev\inmetrics\workspace_branchs\developer\in_automation)
2017-06-14 10:04:47.956  INFO 10216 --- [           main] .a.s.s.r.b.ControleDeReapresentacoesStep : No active profile set, falling back to default profiles: default
2017-06-14 10:04:48.010  INFO 10216 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@3e14c16d: startup date [Wed Jun 14 10:04:48 BRT 2017]; root of context hierarchy
2017-06-14 10:04:50.071  INFO 10216 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration' of type [class org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-06-14 10:04:50.213  INFO 10216 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'validator' of type [class org.springframework.validation.beanvalidation.LocalValidatorFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-06-14 10:04:51.162  INFO 10216 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2017-06-14 10:04:52.454  INFO 10216 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2017-06-14 10:04:52.552 [main] INFO  Mainframe:36 - java.awt.Headless: 'false'
2017-06-14 10:04:52.554 [main] INFO  Mainframe:36 - deviceName: ''
2017-06-14 10:04:52.556 [main] INFO  Mainframe:36 - propFileName: 'mainframeSec.properties'
2017-06-14 10:04:52.655  WARN 10216 --- [           main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'arquivosCommonFuncionalidade': Unsatisfied dependency expressed through field 'tipoArquivo'; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'br.com.cielo.automacao.files.impl.interfaces.TipoArquivo' available: expected single matching bean but found 2: fileCsv,fileTxt
2017-06-14 10:04:52.666  INFO 10216 --- [           main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2017-06-14 10:04:52.680  INFO 10216 --- [           main] utoConfigurationReportLoggingInitializer : 

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-06-14 10:04:52.694 ERROR 10216 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Field tipoArquivo in br.com.cielo.automacao.funcionalidades.arquivos.ArquivosCommonFuncionalidade required a single bean, but 2 were found:
    - fileCsv: defined in file [C:\dev\inmetrics\workspace_branchs\developer\in_automation\target\classes\br\com\cielo\automacao\files\impl\FileCsv.class]
    - fileTxt: defined in file [C:\dev\inmetrics\workspace_branchs\developer\in_automation\target\classes\br\com\cielo\automacao\files\impl\FileTxt.class]

Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

Exception in thread "main" java.lang.IllegalStateException: Failed to load ApplicationContext
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
    at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
    at cucumber.runtime.java.spring.CucumberTestContextManager.getContext(SpringFactory.java:215)
    at cucumber.runtime.java.spring.CucumberTestContextManager.<init>(SpringFactory.java:207)
    at cucumber.runtime.java.spring.SpringFactory.start(SpringFactory.java:102)
    at cucumber.runtime.java.JavaBackend.buildWorld(JavaBackend.java:123)
    at cucumber.runtime.Runtime.buildBackendWorlds(Runtime.java:141)
    at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:38)
    at cucumber.runtime.model.CucumberFeature.run(CucumberFeature.java:165)
    at cucumber.runtime.Runtime.run(Runtime.java:122)
    at cucumber.api.cli.Main.run(Main.java:36)
    at cucumber.api.cli.Main.main(Main.java:18)
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'arquivosCommonFuncionalidade': Unsatisfied dependency expressed through field 'tipoArquivo'; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'br.com.cielo.automacao.files.impl.interfaces.TipoArquivo' available: expected single matching bean but found 2: fileCsv,fileTxt
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
    at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:120)
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
    ... 11 more
Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'br.com.cielo.automacao.files.impl.interfaces.TipoArquivo' available: expected single matching bean but found 2: fileCsv,fileTxt
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveNotUnique(DependencyDescriptor.java:173)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585)
    ... 29 more

TipoArquivo é uma interface, e FileCsv e FileTxt são as classes que implementam essa interface, porém está dando esse erro? O que consisti esse erro? Pesquisei na internet, mas nao entendi muito bem

Obrigado

2 respostas
solução!

Fala Thiago, tudo bem ?

O Spring está tentando montar o contexto da sua aplicação e na hora de resolver uma injeção (provavelmente no ponto onde tem arquivosCommonFuncionalidade) ele encontra mais de um bean disponível, no caso as duas implementações de TipoArquivo -> FileCsv e FileTxt. Então ele solta exception pois não sabe qual deles injetar.

Na stack ele inclusive dá uma dica de como resolver o problema.

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed.

Ele da algumas opções: - Marcar um dos beans com @Primary, pra ele saber qual deve injetar no caso desse conflito. - Fazer com que a classe que recebe a injeção possa suportar mais de um bean do tipo - Usar @Qualifier('umaIdentificação') pra diferenciar os componentes no local onde deseja receber a referência via injeção de dependências

PS: sobre essa última tem um post bacana no blog Domine o Spring que explicar melhor como aplicar => link

Espero ter ajudado. Abraço!

Ok, obrigado Rafael