Announcement Announcement Module
Collapse
No announcement yet.
No bean named 'Test3' is defined Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • No bean named 'Test3' is defined

    Hello,

    I seem to be getting this error:
    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)
    It happens when trying to run this class:
    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();
    	}
    }
    My springconfig4.xml 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>
    And my Test3 class looks like this:
    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;
    	}
    }
    I can't figure out what's wrong, any ideas? I believe there must be something wrong in my configuration file...

  • #2
    It doesn't look like there's an reason for you to get this error except that the class Test3 is not defined under any of the packages com.nortal.pirs.test.independant or com.nortal.pirs.businesslogic.logic. This class has got to be there in one of these two packages.

    Comment

    Working...
    X