spring 小知识

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
    <!-- bean definitions here -->

    <!--开启注解扫描,包含属性注入标签的开启-->
<!--    <context:component-scan base-package="com.imooc"/>-->

    <!--属性注入标签,无需在注入类上加上 Compentent等标志-->
    <context:annotation-config/>

    <bean id="productService" class="com.imooc.demo3.ProductService">
        <!--<property name="productDao" ref="productDao"/>-->
        <!--<property name="categoryDao" ref="categoryDao"/>-->
    </bean>
    <bean id="categoryDao" class="com.imooc.demo3.CategoryDao"/>
    <bean id="productDao" class="com.imooc.demo3.ProductDao"/>
</beans>

<context:annotation-config/> 如果在不添加compent等标志,但是在属性上添加@resource等标志时。使用这个标志可以进行属性注入。

context:component-scan 开启后,包含了annotation-config标签,就无需在添加了

 

<mvc:annotation-driven /> 是一种简写形式,完全可以手动配置替代这种简写形式,简写形式可以让初学都快速应用默认配置方案。<mvc:annotation-driven /> 会自动注册DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter 两个bean,是spring MVC为@Controllers分发请求所必须的。
并提供了:数据绑定支持,@NumberFormatannotation支持,@DateTimeFormat支持,@Valid支持,读写XML的支持(JAXB),读写JSON的支持(Jackson)。
后面,我们处理响应ajax请求时,就使用到了对json的支持。
后面,对action写JUnit单元测试时,要从spring IOC容器中取DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter 两个bean,来完成测试,取的时候要知道是<mvc:annotation-driven />这一句注册的这两个bean。

 

        <!-- 能支持springmvc更高级一些的功能,JSR303校验,快捷的ajax...映射动态请求 -->
        <mvc:annotation-driven/>
        

转载于:https://my.oschina.net/popfei/blog/1845804

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值