Spring框架配置java web實(shí)現(xiàn)實(shí)例化
java_web的IOC的初始化,是在初始化Tomcat時(shí)自動(dòng)配置
配置spring-web。jar(spring.web包)提供的監(jiān)聽(tīng)器,此監(jiān)聽(tīng)器樂(lè)意在服務(wù)器啟動(dòng)是初始化IOC容器
初始化Ioc容易(applicationcontext.xml)
1、必須告訴監(jiān)聽(tīng)器此容易的位置:context_param
2、使用默認(rèn)約定位置,applicationContext.xml必須放在WEB-INF下面且名字必須是這個(gè)名字
代碼如下
<?xml version='1.0' encoding='UTF-8'?><web-app xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns='http://java.sun.com/xml/ns/javaee' xsi:schemaLocation='http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd' version='2.5'> <display-name>web_1</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <!-- 指定IOc容器的位置 --> <context-param> <!-- 監(jiān)聽(tīng)器的父類中 一個(gè)屬性contextConfigLocation,該屬性保存著容器配置文件applicationcontext.xml的位置--> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <listener> <!-- 配置spring-web。jar提供的監(jiān)聽(tīng)器,此監(jiān)聽(tīng)器樂(lè)意在服務(wù)器啟動(dòng)是初始化IOC容器 初始化Ioc容易(applicationcontext.xml),1、必須告訴監(jiān)聽(tīng)器此容易的位置:context_param 2、使用默認(rèn)約定位置,applicationContext.xml必須放在WEB-INF下面且名字必須是這個(gè)名字 --> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener></web-app>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. Java commons-httpclient如果實(shí)現(xiàn)get及post請(qǐng)求2. 一文帶你徹底理解Java序列化和反序列化3. JS中6個(gè)對(duì)象數(shù)組去重的方法4. Python基于requests庫(kù)爬取網(wǎng)站信息5. vscode運(yùn)行php報(bào)錯(cuò)php?not?found解決辦法6. python中文本字符處理的簡(jiǎn)單方法記錄7. PHP laravel實(shí)現(xiàn)導(dǎo)出PDF功能8. Python使用Selenium自動(dòng)進(jìn)行百度搜索的實(shí)現(xiàn)9. PHP利用curl發(fā)送HTTP請(qǐng)求的實(shí)例代碼10. 資深程序員:給Python軟件開(kāi)發(fā)測(cè)試的25個(gè)忠告!

網(wǎng)公網(wǎng)安備