您的位置:首页 > 编程语言 > Java开发

spring 笔记

2016-06-18 19:53 351 查看
















采用Annotation实现AOP(在配置文件中也要进行简单的配置,参考王勇视频)



采用配置文件实现AOP













Spring知识点总结:























44







重点掌握如下方式的spring与struts的整合方式;

2、在web.xml文件中配置ContextLoaderListener,让Web Server在启动的时候将

   BeanFactory放到ServletContext中

  <context-param>

  <param-name>contextConfigLocation</param-name>

  <param-value>classpath:applicationContext-*.xml</param-value>

  </context-param>

  <listener>

<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

  </listener>

3、struts-config.xml文件中<action>标签的type属性需要更改为Spring的代理Action类:org.springframework.web.struts.DelegatingActionProxy

   代理Action的作用:取得BeanFactory,然后到IoC容器中将本次请求对应的Action取出

4、将Action交给Spring创建,必须配置业务逻辑对象,注入给Action

<bean name="/login" class="com.bjpowernode.usermgr.web.actions.LoginAction">

<property name="userManager" ref="userManager"/>

</bean>

* 必须使用name属性,而且name属性的值必须和struts-config.xml文件中<action>标签的path属性值一致

* 必须配置业务逻辑对象

* 建议将scope设置为prototype,这样struts的Action将是线程安全的  





ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");



   

  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  spring java web