spring 依赖性注入 (spring 依赖性注入(xml配置文件,填写的时候要写全,不是包,而是到类)
来源:互联网 发布:linux expr 编辑:程序博客网 时间:2024/05/17 02:40
cn.dao
package cn.dao;public interface PersonDao {public abstract void add();}
cn.dao.imp
package cn.dao;public interface PersonDao {public abstract void add();}
cn.service
package cn.service;public interface PersonService {public abstract void save();}
cn.service.imp
package cn.service.imp;import org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor;import cn.dao.PersonDao;import cn.service.PersonService;public class PersonServiceBean implements PersonService {private PersonDao personDao;public PersonDao getPersonDao() {return personDao;}public void setPersonDao(PersonDao personDao) {this.personDao = personDao;}public void save(){System.out.println("执行save()方法");personDao.add();}}
junit.test
package junit.test;import org.junit.Test;import org.springframework.context.ApplicationContext;import org.springframework.context.support.AbstractApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import cn.service.imp.PersonServiceBean;public class SpringTest {@Test public void instanceSpring(){AbstractApplicationContext ctx=new ClassPathXmlApplicationContext(new String[]{"beans.xml"});PersonServiceBean personServiceBean=(PersonServiceBean) ctx.getBean("personService");personServiceBean.save();ctx.close();}}
beans.xml
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean id="personDao" class="cn.dao.imp.PersonDaoBean"></bean> <bean id="personService" class="cn.service.imp.PersonServiceBean"> <property name="personDao" ref="personDao"></property> </bean></beans>
- spring 依赖性注入 (spring 依赖性注入(xml配置文件,填写的时候要写全,不是包,而是到类)
- spring 依赖性注入 (另一种方法)
- 手动依赖性注入
- Angular 依赖性注入
- JavaEE中的依赖性——依赖性注入
- Spring的注入-从配置文件到注解
- spring bean定义的依赖性检查
- Spring的核心技术(四)---依赖性简介
- spring注入配置文件属性到java类
- spring中的spring.xml配置文件的头文件要是3.0.xsd,如果不是在不支持数组值注入
- Spring之依赖注入与XML配置文件
- 模拟spring的注入和读取配置文件(ApplicationContext.xml)
- 模拟spring的注入和读取配置文件(ApplicationContext.xml)
- Spring @Autowired 注解常用的依赖性接口及数组、Map
- Spring的xml注入实例
- spring-依赖注入 配置文件
- spring 注入之 xml
- Spring xml注入实例
- 多线程
- python自定义解析简单xml格式文件
- <ubuntu 无线网络已禁用 wireless is disabled>解决办法
- kmp
- java.lang.NoClassDefFoundError: org/apache/commons/dbutils/DbUtils
- spring 依赖性注入 (spring 依赖性注入(xml配置文件,填写的时候要写全,不是包,而是到类)
- 《iPhone与iPad开发实战—iOS经典应用剖析》连载一
- TCHAR char CString 数据类型转换
- 十进制二进制互相转换
- python 常用类库!
- 最佳程序设计探索之一:需求驱动编写自顶向下的代码
- 手机ram和rom的区别
- java内存溢出
- (莱昂氏unix源代码分析导读-23) 若干系统调用的实现