第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

Spring整合web開發(fā)

標(biāo)簽:
Java

正常整合Servlet和Spring没有问题的
但是每次执行Servlet的时候加载Spring配置,加载Spring环境.

  • 解决办法:在Servlet的init方法中加载Spring配置文件?

    • 当前这个Servlet可以使用,但是其他的Servlet的用不了了!!!

    • 将加载的信息内容放到ServletContext中.ServletContext对象时全局的对象.服务器启动的时候创建的.在创建ServletContext的时候就加载Spring的环境.

    • ServletContextListener:用于监听ServletContext对象的创建和销毁的.

导入;spring-web-3.2.0.RELEASE.jar
在web.xml中配置:

 <listener>    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param>    <param-name>contextConfigLocation</param-name>    <param-value>classpath:applicationContext.xml</param-value> </context-param>

修改程序的代码:

WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(getServletContext());WebApplicationContext applicationContext = (WebApplicationContext) getServletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);

Spring集成JUnit测试

1.程序中有Junit环境.
2.导入一个jar包.spring与junit整合jar包.

  • spring-test-3.2.0.RELEASE.jar

3.测试代码:

@RunWith(SpringJUnit4Cla***unner.class)@ContextConfiguration(locations="classpath:applicationContext.xml")public class SpringTest {@Autowiredprivate UserService userService;@Testpublic void demo1(){    userService.sayHello();    }}








(1)到(6)总结

Struts2:


Hibernate:知识点比较多.


Spring:AOP. 面向切面的思想.


Spring框架 IOC. AOP . 数据访问 . 集成 . Web

  • IOC:控制反转.将对象的创建权交给Spring.

  • DI:依赖注入.DI需要有IOC环境的,DI在创建对象的时候,将对象的依赖的属性,一并注入到类中


IOC装配Bean:(XML)

  • <bean id=”” class=””/>

  • 配置Bean其他的属性:

    • init-method destroy-method scope

  • DI注入属性:

    • <property name=”属性名” ref=”其他类的id或name”>

    • <property name=”属性名” value=”属性值”>

    • 普通属性:

    • 对象属性:

    • 集合属性的注入:


IOC装配Bean:(注解)

@Component  描述Spring框架中Bean
@Repository 用于对DAO实现类进行标注
@Service 用于对Service实现类进行标注
@Controller 用于对Controller实现类进行标注

DI属性注入

  • 普通属性:

    • @Value

  • 对象属性:

    • AutoWired

    • Resource


Bean的生命周期:

  • 后处理Bean.BeanPostProcessor类.


Spring整合Web项目:


Spring整合Junit测试:


點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評(píng)論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評(píng)論
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消