zoukankan      html  css  js  c++  java
  • Spring的依赖注入的2种方式(1天时间)

    今天花了一天的时间才调试出来

    private      接口   实现类的那个bean;

    最后面的那个名字不能随便的写,必须是配置文件中,实现类的那个bean

    就是后面的那个名字写错了,花了整整一天


    必须有这句注解扫描才能扫描到注解

     


    进行注解的配置,不需要get方法和set方法,小龙儿说xml文件配置才需要set方法


    package com.baobaotao1;
    
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    public class CarServiceImpl implements CarService {
        
         private CarDao carDao;
         public void setCarDao(CarDao carDao) {
              this.carDao = carDao;
       }
    
            public void produceDi(){
                carDao.produceLun();
                System.out.println("閹绘劒绶垫惔鏇犳磸缂佹瑨婧呯�涳拷");
            }
            
            public static void main(String[] args){
            System.out.println(123);    
            ApplicationContext ctx = 
                    new ClassPathXmlApplicationContext("applicationContext.xml"); 
            CarService boss = (CarService) ctx.getBean("carService");
                    boss.produceDi();
            }
    }


    Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'carTest' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'carService' while setting bean property 'carService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'carService' defined in class path resource [applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'carDao' of bean class [com.baobaotao1.CarServiceImpl]: Bean property 'carDao' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

    
    
     

     


  • 相关阅读:
    mysql存储过程
    cms初步构想
    ubuntu 搭建Mercurial 服务(nginx)
    ubuntu 搭建简易的https网站
    【分布式】ZooKeeper权限控制之ACL(Access Control List)访问控制列表
    【分布式】Zookeeper的Leader选举-选举过程介绍(经典的Paxos算法解析)
    【Java 泛型】之 <? super T> 和<? extends T> 中 super ,extends如何理解?有何异同?
    CSS3 圆角(border-radius)
    css去除链接 input 虚框
    关于背景色半透明的实现
  • 原文地址:https://www.cnblogs.com/cs-lcy/p/7360004.html
Copyright © 2011-2022 走看看