计应134 (实验班) 寿燕 spring是java中一种框架,特点是Ioc(控制反转)和AOP(面向切面)。其中Ioc通俗的描述就是不用你自己生成一个对象了,Ioc容器会为你提供,只需向他要(getBean)就可以。配置文件applicationContext.xml,实例化Bean
<bean id="theAction" class="com.cqvie.UpperAction" abstract="false" lazy-init="default" autowire="default" p:message="Hello_"> </bean></beans>
在WEB.XML中添加过滤器,如下
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>
org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>首先定义两个bean:helloBean、dateBean,分别指向HelloBean类和Date类。然后定义了hd1、hd2、hd3等三个bean,都指向HelloDate类。
property标签中的“helloBeanParent”并不存在于beans.xml中,而是在parent.xml中,使用<ref bean="someBean">可以从其它bean配置文件中寻找需要加载的目标bean。bean属性的值可以同目标bean的id属性相同,也可以同它的name属性中任意的一个值相同。
property标签中的“helloBean”如果不存在于beans.xml中,则XML解析器会提示错误。<ref local="someBean">只能这个bean配置文件中寻找需要加载的目标bean,而且local属性值必须同目标bean的id属性相同。
property标签中的“helloBean”同时存在于beans.xml和parent.xml中,使用<ref bean="someBean">则会优先从beans.xml中寻找需要加载的目标bean,如果需要从parent.xml中加载目标bean,则需使用<ref parent="someBean">。在设置date时,使用的是内联bean,这时可以不要任何id或name定义。