久久福利_99r_国产日韩在线视频_直接看av的网站_中文欧美日韩_久久一

您的位置:首頁技術文章
文章詳情頁

Java Spring數據單元配置過程解析

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

基本原理 - 容器和bean

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

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

1. 配置元數據

基于XML的配置元數據的基本結構: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指向的是已經存在該id的bean,alias是給給該bean命的別名--><alias name='userService' alias='user'/>

調用可以通過:

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

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Java
相關文章:
主站蜘蛛池模板: 黄色天堂网 | 九九色综合 | 亚洲一区二区三区 | 久久午夜影院 | av免费网站在线观看 | 国产91亚洲精品久久久 | 91,看片| 免费看的黄色网 | 午夜高清视频 | 99爱免费观看 | 一区二区三区视频 | 久热九九 | 国产成人精品在线 | 亚洲精品日本 | 国产精品人人做人人爽人人添 | 久久一区 | 午夜影院| 一区久久 | 亚洲网站色 | 欧美三级电影在线播放 | 亚洲美女性视频 | 欧美综合在线一区 | 成人综合区 | 中文字幕电影在线 | 午夜精品网站 | 欧美视频在线免费 | 一区二区三区国产视频 | 欧美一级片在线观看 | 欧美精品三区 | 亚洲视频一区二区三区 | 久久久99日产 | 99视频在线免费观看 | 亚洲成人一区二区三区 | 色噜噜视频在线观看 | 亚洲精品一区中文字幕乱码 | 一二三四区视频在线观看 | 亚洲精品成人在线 | 国产成人一区二区 | 成年人精品视频 | 国产成人精品久久 | 日本久久网|