<?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"
 xmlns:jdbc="http://www.springframework.org/schema/jdbc"
 xmlns:jee="http://www.springframework.org/schema/jee"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xmlns:jpa="http://www.springframework.org/schema/data/jpa"
 xmlns:util="http://www.springframework.org/schema/util"
 xmlns:mvc="http://www.springframework.org/schema/mvc"
 xsi:schemaLocation="
  http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
  http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
  http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
  http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
  http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd    
  http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
  http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
  <bean id="egg" class="com.auto.entity.SmallEgg"></bean>
  <bean id="a" class="com.auto.entity.BigEgg"></bean>
  <bean id="rice" class="com.auto.entity.Rice"></bean>
  <!-- 构造器参数注入 -->
  <!-- <bean id="eggAndRice" class="com.auto.entity.EggAndRice">
   <constructor-arg index="0" ref="egg"></constructor-arg>
   <constructor-arg index="1" ref="rice"></constructor-arg>
  </bean> -->
  <!-- set参数注入 -->
  <!-- <bean id="eggAndRice" class="com.auto.entity.EggAndRice">
   <property name="eg" ref="egg"></property>
   <property name="rice" ref="r"></property>
  </bean> -->
  <!-- 自动装配 -->
  <bean id="eggAndRice" class="com.auto.entity.EggAndRice"
   autowire="byName" ></bean>
   
   <bean id="dataSource" class="com.auto.common.DataSource">
    <property name="username" value="#{jdbc.user}"></property>
    <!--SpringEl  -->
    <property name="password" value="#{jdbc.password}"></property>
    <property name="url" value="#{jdbc.url}"></property>
    <property name="driver" value="#{jdbc.driver}"></property>
   </bean>
   <bean id="userDao" class="com.auto.dao.UserDaoImpl" autowire="byName"></bean>
<!--   <bean id="userDao" class="com.auto.dao.MySqlUserdaoImpl" autowire="byName"></bean> -->
   <bean id="userService" class="com.auto.service.UserService" autowire="byName"></bean>
 <!-- 基本参数注入 -->
  <bean id="exam" class="com.auto.entity.ExampleBean">
   <property name="id" value="1"></property>
   <property name="sal" value="222.3"></property>
   <property name="job" value="Information Technology"></property>
   <property name="isMarry" value="true"></property>
  </bean>
 <!-- 集合、键值对属性注入 --> 
  <bean id="exam2" class="com.auto.entity.ExampleBean">
   <property name="objs">
    <list>
     <value>zs</value>
     <bean class="java.util.Date"></bean>
     <bean class="com.auto.entity.Rice"></bean>
    </list>
   </property>
   <property name="sets">
    <set>
     <value>zs</value>
     <value>ls</value>
     <value>zs</value>
    </set> 
   </property>
   
   <property name="maps">
    <map>
     <entry key="a" value="zs"></entry>
     <entry key="b" value-ref="eggAndRice"></entry>
     <entry key="c">
      <bean class="com.auto.entity.Egg"></bean>
     </entry>
    </map>
   </property>
   
   <property name="props">
    <props>
     <prop key="url" >jdbc:oracle:thin:@localhost:1521:xe</prop>
     <prop key="driver">oracle.jdbc.driver.OracleDriver</prop>
     <prop key="a">zs</prop>
    </props>
   </property>
  </bean>
  <!--引用方式注入  -->
  <bean id="exam3" class="com.auto.entity.ExampleBean">
   <property name="objs" ref="list"></property>
   <property name="sets" ref="set"></property>
   <property name="maps" ref="map"></property>
   <property name="props" ref="prop"></property>
  </bean>
  
  
  <util:list id="list" >
   <value>zs</value>
   <bean class="java.util.Date"></bean>
   <bean class="com.auto.entity.Rice"></bean>
  </util:list>
  
  <util:set id="set">
    <value>zs</value>
    <value>ls</value>
    <value>zs</value>
  </util:set>
  
  <util:map id="map">
   <entry key="a" value="zs"></entry>
   <entry key="b" value-ref="eggAndRice"></entry>
   <entry key="c">
    <bean class="com.auto.entity.Egg"></bean>
   </entry>
  </util:map>
  
  <util:properties id="prop">
   <prop key="url" >jdbc:oracle:thin:@localhost:1521:xe</prop>
   <prop key="driver">oracle.jdbc.driver.OracleDriver</prop>
   <prop key="a">zs</prop>
  </util:properties>
  
  <util:properties id="jdbc" location="classpath:com/auto/test/db.properties"></util:properties>
</beans>

转载于:https://www.cnblogs.com/wenwenzuiniucha/p/8573517.html

Spring 之bean的注入相关推荐

  1. spring学习之将类交给spring管理,bean的注入,scope,集合注入,自动装配,生命周期,迟加载

    一.将类交给spring管理(IOC) 1.将类交给spring容器管理 如何将一个类交给spring容器进行管理呢? 方法很简单,只需要在applicationContext.xml中加入对应的xm ...

  2. Spring中bean的注入方式

    平常的Java开发中,程序员在某个类中需要依赖其它类的方法. 通常是new一个依赖类的实例再调用该实例的方法,这种开发存在的问题是new的类实例不好统一管理. Spring提出了依赖注入的思想,即依赖 ...

  3. spring的bean不能注入的几种原因及分析

    1.异常信息 2.有可能引起的原因: 1.在applicationContext.xml的配置文件里的包扫描不对. 2.在web.xml里没有加载spring容器. 3.分布式工程,使用dubbo或者 ...

  4. Spring:Bean依赖注入方式

    目录 1 依赖注入方式 1.1 创建maven工程 pom.xml 1.2 创建bean Student.java Teacher.java 1.3 创建配置文件 applicationContext ...

  5. Spring中bean属性注入方式总结:构造方法、setter注入、p命令空间注入、SpEL注入、集合注入

    1. 构造方法注入 constructor-arg用于配置构造方法一个参数 name :参数的名称 value:设置普通数据 ref:引用数据,一般是另一个bean id值 index :参数的索引号 ...

  6. Spring的Bean实例化、属性注入、对象注入、复杂注入(基于xml配置方式)

    一.Bean实例化的三种方式: (1)使用类的无参构造创建 (2)使用静态工厂创建 (3)使用实例工厂创建 代码实例: (1)项目结构: (2)在pom.xml中导入spring的核心jar包依赖: ...

  7. 单元测试 applicationinfomanager bean无法注入_你真的会用Spring吗?如何在单例Bean中注入原型Bean...

    遇到什么问题 假设单例 BeanA 需要使用原型 BeanB(BeanB 可能是 BeanA 的一个属性值).可是容器仅创建一次单例 BeanA,因此只有一次机会来设置属性 BeanB. @Scope ...

  8. Spring之使用注解实例化Bean并注入属性

    1.准备工作 (1)导入jar包 除了上篇文章使用到的基本jar包外,还得加入aop的jar包,所有jar包如下 所需jar包 (2)配置xml <?xml version="1.0& ...

  9. Spring——Filter过滤器注入Bean时注入失败[NULL]

    问题描述 Spring中Filter注入Bean时注入失败,Bean一直为空. @Slf4j @Component public class RestAuthFilter extends FormAu ...

  10. springMVC通过spring.xml对属性注入bean值(工厂模式)

    springMVC通过spring.xml对属性注入bean值,该bean是一个map容器: <bean id="configXMLCreatorFactory" class ...

最新文章

  1. poj1144(割点)
  2. 谷歌提出新型卷积网络EfficientNet: 推理速度升5.1倍参数减少88%,需要我们的验证
  3. python决策树sklearn_请问python中的sklearn中决策树使用的是哪一种算法呢?
  4. tgz文件linux打开,tgz文件扩展名,tgz文件怎么打开?
  5. 去除div最后一个逗号_去除重复值、统计数量,这个公式可以直接套用!
  6. Archiva 2.2.3 安装运行的时候出现协议版本错误
  7. 数字和为sum的方法数
  8. LabelImg,LabelMe工具标注后的图片数据增强
  9. eprime2.0 倒计时功能
  10. 炫酷3D相册 520七夕情人节表白网页制作(HTML+CSS+JavaScript)
  11. VSCODE同步浏览器刷新
  12. A股上市公司MSCI指数和ESG评级效果(2010-2021年)
  13. java练手代码大全手机版_Java版打字练习游戏源码
  14. 闭合导线的近似平均差(工程测量)
  15. 使用vue+腾讯地图API GL实现地图选房的功能
  16. 【实战】物联网安防监控项目———需求分析
  17. 12.12 Daily Scrum
  18. 微信小程序 发布新版本后 强制升级
  19. 转一个solaris虚拟内存管理的wiki
  20. 1.15 从0开始学习Unity游戏开发--游戏UI

热门文章

  1. SpringAOP之@EnableAspectJAutoProxy如何实现自动代理?
  2. 我们总结了每个技术团队都会遇到的 4 个难题 1
  3. springSecurity 基于方法权限控制@RolesAllowed @Serured @PreAuthorize 与 页面端标签控制权限...
  4. D-Bus 性能分析
  5. [故障解决]Could not get a resource from the pool。
  6. try{return} finally
  7. iOS中分段控制器与UIScrollView结合使用
  8. Android 日历提供器(一)
  9. linux下RRDTool安装方法
  10. 委托作为参数传递时,可以直接传入方法名称