Canary Help

Support and Announcements for the LDS Tech Java Web Application Platform (setup, configuration, bugs, feedback).
tlmaravilla
New Member
Posts: 25
Joined: Tue Feb 01, 2011 5:34 pm
Location: Riverton, UT

Canary Help

Postby tlmaravilla » Mon Feb 07, 2011 11:47 am

I am working on putting my first canary page together with a stack 2.2 RC5 project. I have been following the example in stacks petstore (2.2) and have been able implement the DatabaseServiceMonitor into our project. Where I am struggling is trying to get a SystemServiceMonitor up and running. Here is my unit test:
________________________________________________________________

@ContextConfiguration(locations = "/test-context.xml")
public class SystemServiceMonitorTests extends AbstractTransactionalJUnit4SpringContextTests {

@Autowired
private SystemServiceMonitor sysSvcMntr;

@Test
public void testCheckStatus() throws Exception {
sysSvcMntr.checkStatus();
assertNotNull(sysSvcMntr.getComments());
System.out.println("Comments: " + sysSvcMntr.getComments());

assertNotNull(sysSvcMntr.getStatus());
System.out.println("Status: " + sysSvcMntr.getStatus());
}
}
________________________________________________________________

Here is my implementation of SystemServiceMonitor:

public class SystemServiceMonitor extends BaseCanaryServiceMonitor {

private static final long serialVersionUID = 4501096322032408275L;

@Autowired
private SystemBean systemBean;

public SystemServiceMonitor() {
super();
setName("Build Information");
}

public void checkStatus() {
try {
getComments().add("Build Date: " + systemBean.getBuildDate());
getComments().add("Build Version: " + systemBean.getBuildRevision());
getComments().add("Build Version Info: " + systemBean.getVersionInfo());
setStatus(OK);
}
catch (Exception e) {
setStatus(ERROR);
getComments().add("Unable to retrieve build information: " + e.getMessage());
}
}

@Required
public void setSystemBean(SystemBean systemBean) {
this.systemBean = systemBean;
}
}
________________________________________________________________

Here is test-context.xml:
...
<!-- ### Canary ### -->
<bean class="org.lds.ics.mtm.firewall.service.canary.DatabaseServiceMonitor">
</bean>
<bean class="org.lds.ics.mtm.firewall.service.canary.SystemServiceMonitor">
<property name="systemBean" ref="systemBean" />
</bean>
<bean class="org.lds.stack.template.view.SystemBean">
</bean>

________________________________________________________________

Here is the exception I am seeing via junit when I try and debug:

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.lds.stack.template.view.SystemBean org.lds.ics.mtm.firewall.service.canary.SystemServiceMonitor.systemBean; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.lds.stack.template.view.SystemBean#0' defined in class path resource [test-context.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanInitializationException: Property 'manifest' is required for bean 'org.lds.stack.template.view.SystemBean#0'
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:507)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:283)
... 39 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.lds.stack.template.view.SystemBean#0' defined in class path resource [test-context.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanInitializationException: Property 'manifest' is required for bean 'org.lds.stack.template.view.SystemBean#0'
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:838)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:780)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:697)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)
... 41 more
Caused by: org.springframework.beans.factory.BeanInitializationException: Property 'manifest' is required for bean 'org.lds.stack.template.view.SystemBean#0'
at org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor.postProcessPropertyValues(RequiredAnnotationBeanPostProcessor.java:149)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1064)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
... 50 more

________________________________________________________________

The error is telling me that I need to define a "Resource manifest" property in my systemServiceMonitor bean. I noticed that stack pet store project has a viewBeanContext.xml which defines systemServiceMonitor:

<bean id="systemServiceMonitor" class="org.lds.stack.petstore.service.canary.SystemServiceMonitor">
<property name="systemBean" ref="systemBean"/>
</bean>

I am guessing that ref="systemBean" defines the Resource, where is that bean defined?

YoungstromMJ
Member
Posts: 100
Joined: Mon Mar 29, 2010 2:11 pm
Location: Utah, USA

Postby YoungstromMJ » Mon Feb 07, 2011 4:55 pm

systemBean is defined in stack-template-core.

Just remove the:
<bean class="org.lds.stack.template.view.SystemBean">
</bean>

bean definition and you should be good to go.

Mike

tlmaravilla
New Member
Posts: 25
Joined: Tue Feb 01, 2011 5:34 pm
Location: Riverton, UT

Postby tlmaravilla » Mon Feb 07, 2011 5:01 pm

So I removed that bean and:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.lds.ics.mtm.firewall.service.canary.SystemServiceMonitorTests': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.lds.ics.mtm.firewall.service.canary.SystemServiceMonitor org.lds.ics.mtm.firewall.service.canary.SystemServiceMonitorTests.sysSvcMntr; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.lds.ics.mtm.firewall.service.canary.SystemServiceMonitor#0': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.lds.stack.template.view.SystemBean org.lds.ics.mtm.firewall.service.canary.SystemServiceMonitor.systemBean; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.lds.stack.template.view.SystemBean] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.ann ... .Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1064)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:374)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:110)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:333)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:220)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:301)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:303)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.lds.ics.mtm.firewall.service.canary.SystemServiceMonitor org.lds.ics.mtm.firewall.service.canary.SystemServiceMonitorTests.sysSvcMntr; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.lds.ics.mtm.firewall.service.canary.SystemServiceMonitor#0': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.lds.stack.template.view.SystemBean org.lds.ics.mtm.firewall.service.canary.SystemServiceMonitor.systemBean; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.lds.stack.template.view.SystemBean] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.ann ... .Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:507)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:283)
... 26 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.lds.ics.mtm.firewall.service.canary.SystemServiceMonitor#0': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.lds.stack.template.view.SystemBean org.lds.ics.mtm.firewall.service.canary.SystemServiceMonitor.systemBean; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.lds.stack.template.view.SystemBean] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.ann ... .Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1064)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:838)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:780)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:697)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)
... 28 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.lds.stack.template.view.SystemBean org.lds.ics.mtm.firewall.service.canary.SystemServiceMonitor.systemBean; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.lds.stack.template.view.SystemBean] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.ann ... .Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:507)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:283)
... 39 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.lds.stack.template.view.SystemBean] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.ann ... .Autowired(required=true)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:914)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:783)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:697)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)
... 41 more




Do I need to removed the @Autowired systemBean in my SystemServiceMonitor.java? I will try it and show the results.

tlmaravilla
New Member
Posts: 25
Joined: Tue Feb 01, 2011 5:34 pm
Location: Riverton, UT

Postby tlmaravilla » Mon Feb 07, 2011 5:02 pm

So I removed that @Autowired systemBean statement and:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.lds.ics.mtm.firewall.service.canary.SystemServiceMonitorTests': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.lds.ics.mtm.firewall.service.canary.SystemServiceMonitor org.lds.ics.mtm.firewall.service.canary.SystemServiceMonitorTests.sysSvcMntr; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.lds.ics.mtm.firewall.service.canary.SystemServiceMonitor#0' defined in class path resource [test-context.xml]: Cannot resolve reference to bean 'systemBean' while setting bean property 'systemBean'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'systemBean' is defined
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1064)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:374)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:110)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:333)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:220)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:301)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:303)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.lds.ics.mtm.firewall.service.canary.SystemServiceMonitor org.lds.ics.mtm.firewall.service.canary.SystemServiceMonitorTests.sysSvcMntr; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.lds.ics.mtm.firewall.service.canary.SystemServiceMonitor#0' defined in class path resource [test-context.xml]: Cannot resolve reference to bean 'systemBean' while setting bean property 'systemBean'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'systemBean' is defined
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:507)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:283)
... 26 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.lds.ics.mtm.firewall.service.canary.SystemServiceMonitor#0' defined in class path resource [test-context.xml]: Cannot resolve reference to bean 'systemBean' while setting bean property 'systemBean'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'systemBean' is defined
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1317)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1076)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:838)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:780)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:697)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)
... 28 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'systemBean' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:521)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1068)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:274)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
... 41 more

YoungstromMJ
Member
Posts: 100
Joined: Mon Mar 29, 2010 2:11 pm
Location: Utah, USA

Postby YoungstromMJ » Mon Feb 07, 2011 5:07 pm

Oh, I didn't catch that this was happening in an Integration test before.

Don't use AbstractTransactionalJUnit4SpringContextTests. Use org.lds.stack.spring.test.AbstractTransactionalStackIntegrationTests instead. And use Junit 3 not Junit 4. (I think we talked about this before).

What happens then?

tlmaravilla
New Member
Posts: 25
Joined: Tue Feb 01, 2011 5:34 pm
Location: Riverton, UT

Postby tlmaravilla » Tue Feb 08, 2011 9:28 am

So I updated my test to:

package org.lds.ics.mtm.firewall.service.canary;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;

@ContextConfiguration(locations = "/test-context.xml")
public class SystemServiceMonitorTests extends org.lds.stack.spring.test.AbstractTransactionalCoreStackIntegrationTests {

@Autowired
private SystemServiceMonitor sysSvcMntr;

@Test
public void testCheckStatus() throws Exception {
sysSvcMntr.checkStatus();
assertNotNull(sysSvcMntr.getComments());
System.out.println("Comments: " + sysSvcMntr.getComments());

assertNotNull(sysSvcMntr.getStatus());
System.out.println("Status: " + sysSvcMntr.getStatus());
}
}

and am now using junit 3 and here is my entry in the context file:
<bean class="org.lds.ics.mtm.firewall.service.canary.SystemServiceMonitor">
<property name="systemBean" ref="systemBean" />
</bean>

Here is what I am seeing:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.lds.ics.mtm.firewall.service.canary.SystemServiceMonitorTests': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.lds.ics.mtm.firewall.service.canary.SystemServiceMonitor org.lds.ics.mtm.firewall.service.canary.SystemServiceMonitorTests.sysSvcMntr; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.lds.ics.mtm.firewall.service.canary.SystemServiceMonitor] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.ann ... .Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1064)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:374)
at org.springframework.test.AbstractDependencyInjectionSpringContextTests.injectDependencies(AbstractDependencyInjectionSpringContextTests.java:208)
at org.springframework.test.AbstractDependencyInjectionSpringContextTests.prepareTestInstance(AbstractDependencyInjectionSpringContextTests.java:183)
at org.springframework.test.AbstractSingleSpringContextTests.setUp(AbstractSingleSpringContextTests.java:103)
at junit.framework.TestCase.runBare(TestCase.java:132)
at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:79)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.lds.ics.mtm.firewall.service.canary.SystemServiceMonitor org.lds.ics.mtm.firewall.service.canary.SystemServiceMonitorTests.sysSvcMntr; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.lds.ics.mtm.firewall.service.canary.SystemServiceMonitor] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.ann ... .Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:507)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:283)
... 19 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.lds.ics.mtm.firewall.service.canary.SystemServiceMonitor] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.ann ... .Autowired(required=true)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:914)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:783)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:697)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)
... 21 more

tlmaravilla
New Member
Posts: 25
Joined: Tue Feb 01, 2011 5:34 pm
Location: Riverton, UT

Postby tlmaravilla » Tue Feb 08, 2011 10:51 am

so after some discussions with Mike Y., we have moved our beans from a custom context file: /src/test/resources/test-context.xml to: /src/main/resources/viewBeanContext.xml. Works great now!

MSStringham
New Member
Posts: 2
Joined: Tue Feb 08, 2011 3:42 pm

Postby MSStringham » Tue Feb 08, 2011 3:46 pm

I have following the Canary page coding example from LDS Account and the pet store - in conjunction with Tom Maravilla's work here... and what I see is interesting.

When I hit the /canary page, I see some data. When I refresh the page, the data doubles, then triples, etc.. After about 5 refreshes, I get the following error:

Feb 8, 2011 3:40:41 PM com.atomikos.diagnostics.Slf4jConsole println
WARNING: Connection pool exhausted - try increasing 'maxPoolSize' and/or 'borrowConnectionTimeout' on the DataSourceBean.

Is there a special way in which we need to hook up our datasource, so that we don't gobble up all of our db connections?

tlmaravilla
New Member
Posts: 25
Joined: Tue Feb 01, 2011 5:34 pm
Location: Riverton, UT

Postby tlmaravilla » Tue Feb 08, 2011 4:01 pm

Turns out that we were not closing the connection:

public void checkStatus() {
Connection connection = null;

try {
for (DataSource dataSource : dataSources) {
connection = dataSource.getConnection();
DatabaseMetaData databaseMetaData = connection.getMetaData();
StringBuilder builder = new StringBuilder();
builder.append("Database: ");
builder.append(databaseMetaData.getDatabaseProductVersion());
getComments().add(builder.toString());

builder = new StringBuilder();
builder.append("Driver: ");
builder.append(databaseMetaData.getDriverName());
builder.append(" ");
builder.append(databaseMetaData.getDriverVersion());

getComments().add(builder.toString());
setStatus(OK);
}
}
catch (Exception e) {
setStatus(ERROR);
getComments().add("Database connection failed");
getMessages().add(e.getMessage());
}
finally {
if (connection != null) {
try {
connection.close();
}
catch (SQLException e) {
logger.error("Unable to close DatabaseServiceMonitor database connection.", e);
}
}
}
}

Mike - you may want to update the petstore

YoungstromMJ
Member
Posts: 100
Joined: Mon Mar 29, 2010 2:11 pm
Location: Utah, USA

Postby YoungstromMJ » Tue Feb 08, 2011 4:59 pm

Thanks. I created an issue here: https://tech.lds.org/jira/browse/STACK-3157


Return to “Java Web Project Support (Stack)”

Who is online

Users browsing this forum: No registered users and 1 guest