Spring 配置文件配置 IOC 也叫 DI 在配置文件中创建bean标签,前提是导入pom文件的依赖。
ApplicaitionContext ioc = new ClassPathXmlApplicationContext(“applicationContext.xml”); User user =(User) ioc.getBean("id") user.sayhello() Spring IOC中配置bean属性, 1.属性注入 注:要有无参构造器。默认有,要有set方法 <property name="" values="" > 2.构造器注入 要有有参构造器。 <constrocter-arg> **注解配置**==================================================start========== @service @controller @repository @Controller 需要在配置文件中增加标签扫描包 <context:annotation-scan base-package=“包的位置” > ApplicaitionContext ioc = new ClassPathXmlApplicationContext(“annotation/applicationContext.xml”); User user =(User) ioc.getBean("类名的首字母小写") user.sayhello()