2016-05-16 10 views
3

Spring Beanを使用して継承したクラスを初期化したいとします。私は、継承Spring Inheritance - Annotationを実装するために、このstackoverflowの質問に従っているが、私はこれは私がこの例外注釈を使用したSpring Bean継承Bean参照のバック問題

を取得しています

@Configuration 
public class MaxUsersSAQOSScenarioResultAnalyzer extends DefaultScenarioResultAnalyzer { 

private ScenarioResult scenorioResult; 

@Bean 
public MaxUsersSAQOSScenarioResultAnalyzer maxUsersSAQOSScenarioResultAnalyzer(){ 
    return new MaxUsersSAQOSScenarioResultAnalyzer(); 
} 

public MaxUsersSAQOSScenarioResultAnalyzer() { 
} 

public MaxUsersSAQOSScenarioResultAnalyzer(ScenarioResult scenarioResult) { 
    super(scenarioResult); 
    this.scenorioResult= scenarioResult; 
    setSuccessEmailTemplateId("velocity/scenario/maxusers-saqos-scenario-success.vm"); 
    //scenario failure: use DefaultScenarioResultAnalyzer.failureEmailTemplateId 
} 

に従うよう

public class DefaultScenarioResultAnalyzer implements ScenarioResultAnalyser, CommonConstants{ 
@Autowired 
NotificationEmail notificationEmail; 

@Bean 
public DefaultScenarioResultAnalyzer defaultScenarioResultAnalyzer() { 
    return new DefaultScenarioResultAnalyzer(); 
} 

public DefaultScenarioResultAnalyzer() { 
} 

public DefaultScenarioResultAnalyzer(ScenarioResult scenarioResult) { 
    this.scenarioResult = scenarioResult; 
    this.scenarioId = scenarioResult.getScenarioId(); 
    this.scenarioIdAsString = SCENARIO_FILE_PREFIX + scenarioId; 
} 

私の子供のクラスである私の親クラスである例外

を取得しています

2016-05-16 06:06:50,160 14983 ERROR [main] [org.springframework.test.context.TestContextManager] Caught exception while allowing TestExecutionListener [org.springframewor[email protected]79befb56] to prepare test instance [[email protected]] 
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 org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117) 
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83) 
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:228) 
    at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.springTestContextPrepareTestInstance(AbstractTestNGSpringContextTests.java:149) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86) 
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:514) 
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:215) 
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142) 
    at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:178) 
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108) 
    at org.testng.TestRunner.privateRun(TestRunner.java:782) 
    at org.testng.TestRunner.run(TestRunner.java:632) 
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:366) 
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361) 
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319) 
    at org.testng.SuiteRunner.run(SuiteRunner.java:268) 
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) 
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) 
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244) 
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1169) 
    at org.testng.TestNG.run(TestNG.java:1064) 
    at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72) 
    at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:122) 
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'maxUsersSAQOSScenarioResultAnalyzer' defined in com.asklytics.scenario.MaxUsersSAQOSScenarioResultAnalyzer: factory-bean reference points back to the same bean definition 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:662) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:627) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:597) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1445) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:975) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:752) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) 
    at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:125) 
    at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) 
    at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:109) 
    at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:261) 
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98) 
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116) 
    ... 28 common frames omitted 

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 org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117) 
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83) 
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:228) 
    at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.springTestContextPrepareTestInstance(AbstractTestNGSpringContextTests.java:149) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86) 
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:514) 
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:215) 
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142) 
    at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:178) 
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108) 
    at org.testng.TestRunner.privateRun(TestRunner.java:782) 
    at org.testng.TestRunner.run(TestRunner.java:632) 
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:366) 
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361) 
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319) 
    at org.testng.SuiteRunner.run(SuiteRunner.java:268) 
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) 
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) 
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244) 
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1169) 
    at org.testng.TestNG.run(TestNG.java:1064) 
    at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72) 
    at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:122) 
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'maxUsersSAQOSScenarioResultAnalyzer' defined in com.asklytics.scenario.MaxUsersSAQOSScenarioResultAnalyzer: factory-bean reference points back to the same bean definition 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:662) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:627) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:597) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1445) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:975) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:752) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) 
    at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:125) 
    at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) 
    at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:109) 
    at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:261) 
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98) 
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116) 
    ... 28 

さらに

答えて

9

私の意見では、問題は、Springが2つの異なるBeanを同じ名前で作成しようとしていることです。デフォルトでは、@Component注釈(他の注釈(@Configuration,など)も含めて@Componentというアノテーションが付いているため)を定義すると、その名前はcamelCaseのクラス名になります。

@Bean注釈を使用してBeanを定義する場合、その名前は注釈付きメソッドの名前です。

だから、あなたは二つのこと

あなたは[

@Configuration("maxUsersSAQOSScenarioResultAnalyzerFactory") 

または

+0

何か他のものに@Beanアノテーション付きメソッドの名前を変更、注釈のプロパティを設定することによって、これはJiraをConfiguration Bean名を設定することができますいずれかを行うことができます問題](https://jira.spring.io/browse/SPR-15775)では、この問題を非常にうまく説明しています。 – jtcotton63

関連する問題