欢迎来到天天文库
浏览记录
ID:25788524
大小:283.51 KB
页数:9页
时间:2018-11-22
《ring框架学习总结》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、1.使用jar包spring.jarcommons-logging.jar使用aopaspectjweaver.jar,aspectjrt.jar,cglib-nodep-2.1_3.jar使用注解common-annotations.jar2.实例化容器ApplicationContextcontext=newClassPathXmlApplicationContext(newString[]{“beans.xml”});ApplicationContextcontext=newClassPathXmlApplicationContext(“beans.xml”);Application
2、Contextcontext=newFileSystemXmlApplicationContext(newString[]{“d:\beans.xml”});3.事务@Transactional(propagation=Propagation.Required)4.1)单例模式下singleton:默认情况下,加载beans.xml实例化各个bean//验证:构造方法中输出信息通过来延迟初始化bean,这时,只有第一次获取bean时才初始化2)scope=prototype时,getBean(“”)时实例化bean3、ean...init-method=“method”>加载实例后,执行method方法关闭容器后,执行method1方法三种实例化bean的方式1使用类构造器实例化2.使用静态工厂方法实例化publicclassOrdreFactory{publicstaticOrderFactorycreateOrder(){returnnewOrd4、erServiceBean();}}3.使用实例工厂方法实例化publicclassOrdreFactory{publicOrderFactorycreateOrder(){returnnewOrderServiceBean();}}依赖注入——手工装配@Autowired或@Resource注解方式进行装配5、,common-annotations.jar这两个注解的区别:@Autowired默认按类型装配,@Resource默认按名称装配,当找不到与名称匹配的bean才会按类型装配Beans.xml导入1)publicclassPersonServiceBeanimplementsPersonService{@Resource//默认按名称装配,当找不到与名称匹配的bean才会按类型装配privatePe6、rsonDaopersonDao;publicvoidtest(){personDao.add();}}2)publicclassPersonServiceBeanimplementsPersonService{@Resource(name=”personDao”)privatePersonDaopersonDao;publicvoidtest(){personDao.add();}}3)publicclassPersonServiceBeanimplementsPersonService{privatePersonDaopersonDao;@ResourcepublicvoidsetPe7、rsonDao(PersonDaopersonDao){this.personDao=personDao;}publicvoidtest(){personDao.add();}}Spring自动扫描和管理beanSpring2.5后Beans.xml加入://指定包下所有类1)@Service//getBean(“personServiceB
3、ean...init-method=“method”>加载实例后,执行method方法关闭容器后,执行method1方法三种实例化bean的方式1使用类构造器实例化2.使用静态工厂方法实例化publicclassOrdreFactory{publicstaticOrderFactorycreateOrder(){returnnewOrd
4、erServiceBean();}}3.使用实例工厂方法实例化publicclassOrdreFactory{publicOrderFactorycreateOrder(){returnnewOrderServiceBean();}}依赖注入——手工装配@Autowired或@Resource注解方式进行装配
5、,common-annotations.jar这两个注解的区别:@Autowired默认按类型装配,@Resource默认按名称装配,当找不到与名称匹配的bean才会按类型装配Beans.xml导入1)publicclassPersonServiceBeanimplementsPersonService{@Resource//默认按名称装配,当找不到与名称匹配的bean才会按类型装配privatePe
6、rsonDaopersonDao;publicvoidtest(){personDao.add();}}2)publicclassPersonServiceBeanimplementsPersonService{@Resource(name=”personDao”)privatePersonDaopersonDao;publicvoidtest(){personDao.add();}}3)publicclassPersonServiceBeanimplementsPersonService{privatePersonDaopersonDao;@ResourcepublicvoidsetPe
7、rsonDao(PersonDaopersonDao){this.personDao=personDao;}publicvoidtest(){personDao.add();}}Spring自动扫描和管理beanSpring2.5后Beans.xml加入://指定包下所有类1)@Service//getBean(“personServiceB
此文档下载收益归作者所有