亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術(shù)文章
文章詳情頁

Java Spring數(shù)據(jù)單元配置過程解析

瀏覽:4日期:2022-08-19 15:08:26

基本原理 - 容器和bean

在Spring中,那些組成你應(yīng)用程序的主體(backbone)及由Spring IoC容器所管理的對象,被稱之為bean。 簡單地講,bean就是由Spring容器初始化、裝配及管理的對象,除此之外,bean就與應(yīng)用程序中的其他對象沒有什么區(qū)別了。

也就是說,其實spring 就是在加載配置文件beans.xml的時候,通過反射機(jī)制,去實例化<bean>標(biāo)簽里面的類的過程。這里可以通過在類的默認(rèn)無參構(gòu)造方法中寫點東西判斷出來。

1. 配置元數(shù)據(jù)

基于XML的配置元數(shù)據(jù)的基本結(jié)構(gòu):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 class='...'> <!-- collaborators and configuration for this bean go here --> </bean> <bean class='...'> <!-- collaborators and configuration for this bean go here --> </bean> <!-- 更多的bean的時候 在引用的xml文件一定是要帶spring dtd頭的文件--> <import resource='services.xml'/></beans>

services.xml

在配置文件里面命名其實id 和name都是一樣的

<?xml version='1.0' encoding='UTF-8'?><beans xmlns='http://www.springframework.org/schema/beans' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:context='http://www.springframework.org/schema/context' xmlns:tx='http://www.springframework.org/schema/tx' xsi:schemaLocation='http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd'> <bean name='userService' class='com.sun.service.UserService'><property name='name'> <value>sunxin</value></property></bean></beans>

2. 實例化容器

ApplicationContext context = new ClassPathXmlApplicationContext(new String[] {'beans.xml'});

3. bean的別名

<!--name指向的是已經(jīng)存在該id的bean,alias是給給該bean命的別名--><alias name='userService' alias='user'/>

調(diào)用可以通過:

UserService us = (UserService) app.getBean('user');

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Java
相關(guān)文章:
主站蜘蛛池模板: 成年人在线观看视频网站 | 91精品国产亚一区二区三区 | 尤物视频在线观看免费 | 欧美日韩第一区 | 国产丰满主播丝袜勾搭秀 | 欧洲色综合 | 日韩毛片 | 一本大道在线观看 | 毛片中文字幕 | 欧美日韩一区二区综合 | 在线欧洲成人免费视频 | 亚洲欧美日本人成在线观看 | 999久久66久6只有精品 | 久久er热在这里只有精品85 | 国产大学生一级毛片绿象 | 中文字幕久久久久一区 | 国产一区影视 | 簧片免费网站 | 国产精品玖玖玖影院 | 亚洲制服在线观看 | 国产成人在线看 | 国产成人啪精品午夜在线播放 | 免费国产一区二区在免费观看 | 欧美伦理一区 | 免费看一级特黄a大片 | 伊人狠狠丁香婷婷综合色 | 91精品国产免费网站 | a级精品国产片在线观看 | 欧美亚洲日本国产 | 激情小视频在线播放免费 | 亚洲综合色站 | 亚洲精品麻豆一区二区 | 国产精品久久免费观看 | 国产成人精品s8p视频 | 无遮挡一级毛片呦女视频 | 久久亚洲国产最新网站 | 亚洲一区二区约美女探花 | 国产无内制服肉丝精品视频 | 非洲一区二区三区不卡 | 中文字幕一区二区在线视频 | 9久9久女女免费精品视频在线观看 |