springÖжÁÈ¡xmlÅäÖÃÎļþ¡¢»ñÈ¡beanµÄ¼¸ÖÖ·½Ê½
»ñÈ¡Spring¿ò¼Ü¹ÜÀíµÄÀàʵÀýµÄ·½·¨ÓжàÖÖ,ÈçÏ£º
·½·¨Ò»£ºÔÚ³õʼ»¯Ê±±£´æApplicationContext¶ÔÏó
´úÂ룺
ApplicationContext ac = new FileSystemXmlApplicationContext("applicationContext.xml");
ac.getBean("beanId");
˵Ã÷£º
ÕâÖÖ·½Ê½ÊÊÓÃÓÚ²ÉÓÃSpring¿ò¼ÜµÄ¶ÀÁ¢Ó¦ÓóÌÐò£¬ÐèÒª³ÌÐòͨ¹ýÅäÖÃÎļþÊÖ¹¤³õʼ»¯SpringµÄÇé¿ö¡£
·½·¨¶þ£ºÍ¨¹ýSpringÌṩµÄ¹¤¾ßÀà»ñÈ¡ApplicationContext¶ÔÏó
´úÂ룺
import org.springframework.web.context.support.WebApplicationContextUtils;
ApplicationContext ac1 = WebApplicationContextUtils.getRequiredWebApplicationContext(ServletContext sc)
ApplicationContext ac2 = WebApplicationContextUtils.getWebApplicationContext(ServletContext sc)
ac1.getBean("beanId");
ac2.getBean("beanId");
˵Ã÷£º
ÕâÖÖ·½Ê½ÊʺÏÓÚ²ÉÓÃSpring¿ò¼ÜµÄB/Sϵͳ£¬Í¨¹ýServletContext¶ÔÏó»ñÈ¡ApplicationContext¶ÔÏó£¬È»ºóÔÚͨ¹ýËü»ñÈ¡ÐèÒªµÄÀàʵÀý¡£
ÉÏÃæÁ½¸ö¹¤¾ß·½Ê½µÄÇø±ðÊÇ£¬Ç°ÕßÔÚ»ñȡʧ°ÜʱÅ׳öÒì³££¬ºóÕß·µ»Ønull¡£
·½·¨Èý£º¼Ì³Ð×Ô³éÏóÀàApplicationObjectSupport
˵Ã÷£º
³éÏóÀàApplicationObjectSupportÌṩgetApplicationContext()·½·¨£¬¿ÉÒÔ·½±ãµÄ»ñÈ¡µ½ApplicationContext¡£Spring³õʼ»¯Ê±£¬»áͨ¹ý¸Ã³éÏóÀàµÄsetApplicationContext(ApplicationContext context)·½·¨½«ApplicationContext ¶ÔÏó×¢Èë¡£
·½·¨ËÄ£º¼Ì³Ð×Ô³éÏóÀàWebApplicationObjectSupport
˵Ã÷£º
ÀàËÆÉÏÃæ·½·¨£¬µ÷ÓÃgetWebApplicationContext()»ñÈ¡WebApplicationContext
·½·¨Î壺ʵÏÖ½Ó¿ÚApplicationContextAware
˵Ã÷£º
ʵÏָýӿڵÄsetApplicationContext(ApplicationContext context)·½·¨£¬²¢±£´æApplicationContext ¶ÔÏó¡£Spring³õʼ»¯Ê±£¬»áͨ¹ý¸Ã·½·¨½«ApplicationContext ¶ÔÏó×¢Èë¡£
ÒÔÉÏ·½·¨Êʺϲ»Í¬µÄÇé¿ö£¬Çë¸ù¾Ý¾ßÌåÇé¿öÑ¡ÓÃÏàÓ¦µÄ·½·¨¡£
ÕâÀïÖµµÃÌáÒ»µãµÄÊÇ£¬ÏµÍ³ÖÐÓõ½ÉÏÊö·½·¨µÄÀàʵ¼ÊÉϾÍÓÚSpring¿ò¼Ü½ôÃÜñîºÏÔÚÒ»ÆðÁË£¬ÒòΪÕâЩÀàÊÇÖªµÀËüÃÇÊÇÔËÐÐÔÚSpring¿ò¼ÜÉϵģ¬Òò´Ë£¬ÏµÍ³ÖУ¬Ó¦¸Ã¾¡Á¿µÄ¼õÉÙÕâÀàÓ¦Óã¬Ê¹ÏµÍ³¾¡¿ÉÄܵĶÀÁ¢ÓÚµ±Ç°ÔËÐл·¾³£¬¾¡Á¿Í¨¹ýDIµÄ·½Ê½»ñÈ¡ÐèÒªµÄ·þÎñÌṩÕß¡£
±¾ÈËÈÏΪ£¬·½·¨Îå±È½Ï¿ÉÐУ¬¿ÉÒÔÉè¼ÆÒ»¸ö¹¤¾ßÀ࣬רÃÅÀ´»ñÈ¡SpringÖеÄÀà¡£¼õÉÙ¶ÔÒµÎñ´úÂëµÄÇÖÈëÐÔ¡£
¶ÁÈ¡xmlÎļþ
/**
* ÀûÓÃXmlBeanFactory(Resource resource)
* ÕâÀïResource±
Ïà¹ØÎĵµ£º
ÓÐÈË»áÎÊ£¬DTDºÍSchema¶¼ÊǶÔXMLÎĵµµÄÒ»ÖÖÔ¼Êø£¬ÎªÊ²Ã´²»¾ÍÑ¡ÆäÖÐÖ®Ò»£¬¶øÓÖÓÐSchemaÄØ¡£ÒòΪDTD°²È«¶ÈÌ«µÍÁË£¬Ò²¾ÍÊÇ˵ËüµÄÔ¼Êø¶¨ÒåÄÜÁ¦²»×㣬ÎÞ·¨¶ÔXMLʵÀýÎĵµ×ö³ö¸üϸÖµÄÓïÒåÏÞÖÆ¡£ÆäʵϸÐĵÄÈ˻ᷢÏÖ£¬ÔÚDTDÖУ¬Ö»ÓÐÒ»¸öÊý¾ÝÀàÐÍ£¬¾ÍÊÇPCDATA£¨ÓÃÔÚÔªËØÖУ©ºÍCDATA£¨ÓÃÔÚÊôÐÔÖУ©£¬ÔÚÀïÃæдÈÕÆÚÒ²ÐУ¬Êý×Ö»¹ÐУ¬×Ö·û ......
protected void Button1_Click(object sender, EventArgs e)
{
//Ϊresponse(star)½Úµã ºÍ Cabins(f) cabin½Úµã·Ö±ðÌí¼Ó¸ö
&nbs ......
XML Schema ²Î¿¼ÊÖ²á
XSD ÔªËØ
ÔªËØ
½âÊÍ
all
¹æ¶¨×ÓÔªËØÄܹ»ÒÔÈÎÒâ˳Ðò³öÏÖ£¬Ã¿¸ö×ÓÔªËؿɳöÏÖÁã´Î»òÒ»´Î¡£
annotation
annotation ÔªËØÊÇÒ»¸ö¶¥²ãÔªËØ£¬¹æ¶¨ schema µÄ×¢ÊÍ¡£
any
ʹ´´×÷Õß¿ÉÒÔͨ¹ýδ±» schema ¹æ¶¨µÄÔªËØÀ´À©Õ¹ XML Îĵµ¡£
anyAttribute
Ê ......
/**
* ftpÉÏ´«ÎļþJavaBean
* @author Administrator
*
*/
public class FtpBean {
//ftp·þÎñµØÖ·
private String ftpUrl="";
//ftp̞
private String userName="";
//ftpÃÜÂë
private String passWord="";
public String getF ......
3£©¶ÁÈ¡¡¢²éÕÒ
µ±ÄãÊÖÍ·ÓÐÒ»¸öxmlÎļþºó£¬¿ÉÒÔʹÓÃXmlDocument.Load()·½·¨½«Æä¼ÓÔؽøÀ´ÒԱ㴦Àí£¬ËùÒÔ“¶ÁÈ¡”ûÓÐʲô¿É˵µÄ¡£¶ø“²éÕÒ”²Ù×÷ÍùÍùÉæ¼°XPath£¬ÕâÀïÖ»ÊÇÎÒÈÏΪµÄ±È½Ï³£Óõ½µÄ²éÕÒ²Ù×÷£¬XPathÕâÍæÒâʵÔÚÊǺÜÇ¿´óºÜ±©Á¦¡£
»ØÍ·¿´Ê¾ÀýÎĵµxmlsample.xml£¬ÎÒÃÇ¿ÉÄÜÓöµ½ÕâÑùµÄÐèÇó£ ......