av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

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

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

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

基本原理 - 容器和bean

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

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

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的時(shí)候 在引用的xml文件一定是要帶spring dtd頭的文件--> <import resource='services.xml'/></beans>

services.xml

在配置文件里面命名其實(shí)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. 實(shí)例化容器

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)文章:
主站蜘蛛池模板: 丁香婷婷在线 | 538精品视频 | 日韩一区二区三区四区 | 国产综合久久久 | 日韩精品成人 | 91精品在线播放 | 欧美精品色 | 亚洲小视频在线观看 | 成人午夜激情 | 午夜精品国产精品大乳美女 | 国产福利91 | 亚洲精品网站在线观看 | 18视频在线观看男男 | 亚洲精品一区二区三区精华液 | 求av网站 | 国产小视频在线播放 | 国产三级久久 | 亚洲午夜18毛片在线看 | 日本免费黄色 | 成人av一区 | 国产盗摄一区二区三区 | 久热精品视频在线观看 | 在线亚洲一区 | 国产精品成人免费视频 | 欧美性生交xxxxx | 精品一区视频 | 一区二区视频在线 | 蜜臀av中文字幕 | 国产全肉乱妇杂乱视频 | 欧美一二区 | 天天躁日日躁bbbbb | 少妇高潮av久久久久久 | 91桃色网站| 欧美日韩中文 | 天天操天天舔 | 国产精品一区二区三区四区五区 | 亚洲精品综合 | 日韩一区二区三区在线 | 久久国产精 | 在线观看h片 | 午夜免费观看视频 |