• spring基础


    XML文件:

    <?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:aop="http://www.springframework.org/schema/aop"
    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
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd ">


    <context:annotation-config/>
    <context:component-scan base-package="com.twsm"/>


    </beans>


    spring基础:

    1.注入类型:setter注入 构造参数注入 接口注入

    <bean id="ud" class="com.twsm.dao.UserDao"></bean>
    <bean id="userService" class="com.twsm.service.UserService">
    <!-- setter 注入 -->
    <property name="userDao" ref="ud"></property>
    <!-- 构造参数注入 -->
    <constructor-arg index="0" ref="ud"></constructor-arg>
    </bean>

    调用:
    ApplicationContext ctx = new ClassPathXmlApplicationContext("user-spring.xml");
    UserService service = (UserService)ctx.getBean("userService");
    service.addUser(u);


    2. id 和 name基本可以通用,区别在于 name中可以包含一些特殊字符


    3.annotation:

    需要配置XML开启 annotation 功能
    <context:annotation-config/>

    1. @AutoWired(默认按类型) @Qualifier
    2. @Resource(name="userDao")(默认按类名名称)
    3. 组件: @componnent @service @controller @reponstory

  • 相关阅读:
    猜数游戏
    计算数组长度
    python 将IP地址转换成打包后的32位格式
    nutch-2.2.1 hadoop-1.2.1 hbase-0.92.1 集群部署
    Julien Nioche谈Apache Nutch 2的特性及产品路线图
    一次心惊肉跳的服务器误删文件的恢复过程
    Http长连接200万尝试及调优
    zookeeper 系列
    Enhancing the Scalability of Memcached
    linux杂谈(十八):DNS服务器的配置(一)
  • 原文地址:https://www.cnblogs.com/xiangjune/p/6566401.html
Copyright © 2020-2023  润新知