Hello,
I seem to be getting this error:
It happens when trying to run this class:Code:Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'Test3' is defined at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:553) at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1095) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:277) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1098) at com.nortal.pirs.test.independant.Test4.main(Test4.java:12)
My springconfig4.xml looks like this:Code:public class Test4 { public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("com/nortal/pirs/beans/springconfig4.xml"); BeanFactory factory = context; Test3 instance = (Test3) factory.getBean("Test3"); instance.run(); } }
And my Test3 class looks like this:Code:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"> <context:annotation-config/> <context:component-scan base-package="com.nortal.pirs.test.independant"></context:component-scan> <context:component-scan base-package="com.nortal.pirs.businesslogic.logic"></context:component-scan> </beans>
I can't figure out what's wrong, any ideas? I believe there must be something wrong in my configuration file...Code:@Component public class Test3 { @Autowired private UserManagerLogic userManager; public void run() { System.out.println("I'm finally wired: " + userManager.getNumberOfUsers()); } public void setUserManager(UserManagerLogic userManager) { this.userManager = userManager; } }


Reply With Quote
