通过静态工厂的方法创建bean;和实例工厂方法:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- 通过静态工厂的方法来配置bean ,注意不是配置静态工厂的实例,而是配置bean的实例 -->
<!-- class 属性:指向的是静态工厂方法的全类名
factory-method :指向的是静态工厂方法的名字
constructor-arg:如果工厂方法需要传入参数,则使用constructor-arg来配置参数 -->
<bean id="car" class="lib2.Car"
factory-method="gerCae">
<constructor-arg value="audi"></constructor-arg></bean>
<!-- 配置工厂的实例 -->
<bean id="casec" class="instance"></bean>
<!-- 通过实例工厂方法来配置bean -->
<!-- factory-bean: 属性:指向的是静态工厂方法的bean
factory-method :指向的是静态工厂方法的名字
constructor-arg:如果工厂方法需要传入参数,则使用constructor-arg来配置参数 -->
<bean id="cae" factory-bean="cad" factory-method="cac">
<constructor-arg value="asca"></constructor-arg></bean> </beans>

factory来配置bean。创建类的时候要继承接口

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!--
通过factorybean来配置bean的实例
class:只想factorybean的全类名
property:配置的事factorybean的属性(可能是里面的复制函数set) -->
<bean id="Car" class="factorybean">
<property name="brand" value="bwm"></property></bean> </beans>

基于注解来配置bean和bean的线相关的属性。

组件扫描:spring能够从classpath夏自动扫描、侦测和实例化具有特定注释的组件;

package test1;

import org.springframework.stereotype.Component;

@Component
public class TestObject { }
package test2; import org.springframework.stereotype.Repository; @Repository
public class UserReposityImpl implements UserRepository { @Override
public void save() {
// TODO Auto-generated method stub
System.out.println("UserRepository save...."); }
}package test3; import org.springframework.stereotype.Service; @Service
public class UserService {
public void add()
{
System.out.println("UserSerivce add..");
} }
package test4; import org.springframework.stereotype.Controller; @Controller
public class UserController {
public void execute()
{
System.out.println("UserController execute..");
}
}
<?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-4.3.xsd">
<!-- 指定spring ioc容器扫描的包 -->
<context:component-scan base-package="test1.TestObject"></context:component-scan> </beans>
package test1; import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import test2.UserRepository;
import test3.UserService;
import test4.UserController; public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
ApplicationContext ct=new ClassPathXmlApplicationContext("beans-053.xml");
TestObject to=(TestObject) ct.getBean("testObject");
UserController userController=(UserController) ct.getBean("userController");
UserRepository userRepository=(UserRepository) ct.getBean("userRepository");
UserService userService=(UserService) ct.getBean("userService");
System.out.println(to);
System.out.println(userController);
System.out.println(userService);
System.out.println(userRepository); }
}

关于MyBeanPostProcessor的应用。

spring05的更多相关文章

  1. Spring-05 使用注解开发

    Spring-05 使用注解开发 使用注解开发 1.项目准备 在spring4之后,想要使用注解形式,必须得要引入aop的包5 <!-- https://mvnrepository.com/ar ...

  2. spring05配置文件之间的关系

    一:配置文件包含关系 1.创建对应的实体类 public class Student { //学生实体类 private String name; //姓名 private Integer age; ...

  3. Spring-05 -AOP [面向切面编程] -Schema-based 实现aop的步骤

    一.AOP [知识点详解] AOP:中文名称面向切面编程 英文名称:(Aspect Oriented Programming) 正常程序执行流程都是纵向执行流程 3.1 又叫面向切面编程,在原有纵向执 ...

  4. Spring05——Spring 如何实现事务管理

    在此之前,我们已经了解了 Spring 相关的基础知识,今天将为给位带来,有关 Spring 事务代理的相关知识.关注我的公众号「Java面典」,每天 10:24 和你一起了解更多 Java 相关知识 ...

  5. 玩转spring boot——结合JPA入门

    参考官方例子:https://spring.io/guides/gs/accessing-data-jpa/ 接着上篇内容 一.小试牛刀 创建maven项目后,修改pom.xml文件 <proj ...

  6. Spring:AOP面向切面编程

    AOP主要实现的目的是针对业务处理过程中的切面进行提取,它所面对的是处理过程中的某个步骤或阶段,以获得逻辑过程中各部分之间低耦合性的隔离效果. AOP是软件开发思想阶段性的产物,我们比较熟悉面向过程O ...

  7. Spring实现Ioc的多种方式--控制反转、依赖注入、xml配置的方式实现IoC、对象作用域

    Spring实现Ioc的多种方式 一.IoC基础 1.1.概念: 1.IoC 控制反转(Inversion of Control) IoC是一种设计思想. 2.DI 依赖注入 依赖注入是实现IoC的一 ...

  8. Spring4学习回顾之路10-Spring4.x新特性:泛型依赖注入

    泛型依赖注入:Spring 4.x中可以为子类注入子类对应的泛型类型的成员变量的引用. 话语太过抽象,直接看代码案例,依次建立如下代码: User.java package com.lql.sprin ...

  9. 环绕通知(xml)

    1.maven依赖 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="h ...

随机推荐

  1. js中 navigator 对象

    Navigator 对象包含有关浏览器的信息. 很多时候我们需要在判断网页所处的浏览器和平台,Navigator为我们提供了便利 Navigator常见的对象属性如下: 属性 描述 appCodeNa ...

  2. MySQL记录操作(增删改)

    概览 MySQL数据操作: DML 在MySQL管理软件中,可以通过SQL语句中的DML语言来实现数据的操作,包括 使用INSERT实现数据的插入 UPDATE实现数据的更新 使用DELETE实现数据 ...

  3. vue列表中表单的验证

    先上效果图: 在点击确认的时候会验证带有验证的字段 嵌套逻辑: 表单 表格 表格项 表单项 表单项 表格项 表格 表单 代码部分: <!-- 注意此处的model,需要一个对象,而我们的数据是一 ...

  4. 前端基础面试题(js部分)

      前端基础面试题(JS部分)   1.几种基本数据类型?复杂数据类型?值类型和引用数据类型?堆栈数据结构? 基本数据类型:Undefined.Null.Boolean.Number.String值类 ...

  5. (转)协议森林07 傀儡 (UDP协议)

    协议森林07 傀儡 (UDP协议) 作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 我们已经讲解了物理层.连接层和网络层.最开始的 ...

  6. created:异步初始化数据都应该放到 created里面

    created:异步初始化数据都应该放到 created里面

  7. java -封装一个类。(姓名、年龄、性别)

    //定义一个类. public class Maopao1{ //创建私有的对象. private String name; private int age; private String sex; ...

  8. python迭代器、装饰器和生成器

    装饰器 1.装饰器的作用 1. 装饰器作用:本质是函数(装饰其他函数)就是为其他函数添加其他功能 2. 装饰器必须准寻得原则: 1)不能修改被装饰函数的源代码 2)不能修改被装饰函数的调用方式 3.实 ...

  9. git常用命令学习配详细说明

    原文链接 把当前目录变成Git可以管理的仓库 git init 查看仓库当前的状态 git status 添加新/变动文件 git add <文件名> // 添加某个新文件(目录) git ...

  10. 理解Go语言组件flag

    作用 主要用来实现命令行的参数解析,以达到实现以下效果的目的 $ cmd -flagname 123 使用方式 flag是Go语言的内置包,能接收的参数类型主要有字符串.布尔和数值类型. 方式一 fu ...