public class StudentBusinessImpl implements IstudentBusiness {    private StudentDAO studentdao;    public void setStudentdao(StudentDAO studentdao) {
        this.studentdao = studentdao;
    }    public StudentDAO getStudentdao() {
        return studentdao;
    } <bean id="jdbcTemplate"  class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="dataSource" />
    </bean>    <bean id="studentBusiness" class="com.demo.my.business.impl.StudentBusinessImpl">
        <property name="studentdao" ref="notallkown"/>
    </bean>
    
    <bean  id="studentDAO" class="com.demo.my.dao.impl.StudentDaoImpl">
        <property name="jdbcTemplate" ref="jdbcTemplate"/>
    </bean>  public static void main(String[] args) {
        getInfo();
    }    public static void getInfo() {
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
        IstudentBusiness studentB= (IstudentBusiness) ac.getBean("studentBusiness");
        Student students = studentB.getInfo(111);        System.out.print(students.getName() + "\n" + students.getStuID());    } 运行后报错:Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'studentBusiness' is defined我不知道该怎么解决了!

解决方案 »

  1.   

    StudentBusinessImpl是com.demo.my.business.impl下吗?
      

  2.   


        <bean id="studentBusiness"      class="com.demo.my.business.impl.StudentBusinessImpl"> 
            <property name="studentdao" ref="studentDAO"/> 
        </bean> 
        
        <bean  id="studentDAO" class="com.demo.my.dao.impl.StudentDaoImpl"> 
            <property name="jdbcTemplate" ref="jdbcTemplate"/> 
        </bean> try it now!
      

  3.   

    <property name="studentdao" ref="notallkown"/> 注入的类对吗?
    加载applicationContext.xml没报错?
      

  4.   

    <bean id="studentBusiness" class="com.demo.my.business.impl.StudentBusinessImpl">
            <property name="studentdao" ref="notallkown"/>
    </bean>红色部分的哪来的 ,改为ref="studentDAO" 
      

  5.   

    我已近找到错误了
    原来我有两个applicationContext.xml
    一个在web-inf下
    一个在更目录下!
    里面的内容不一样!读取了我没有配置的那个applicationContext.xml
      

  6.   

    <bean id="studentBusiness" class="com.demo.my.business.impl.StudentBusinessImpl">
            <property name="studentdao" ref="studentdao"/>
        </bean>
       
        <bean  id="studentdao" class="com.demo.my.dao.impl.StudentDaoImpl">
            <property name="jdbcTemplate" ref="jdbcTemplate"/>
        </bean> 
      

  7.   

     <bean id="StudentBusinessImpl "class="com.demo.my.business
            .impl.StudentBusinessImpl"> 
            <property name="studentdao" ref="notallkown"/> 
     </bean> 
    替换你的试一下