架构师之路:Spring高效开发带前后端开发完整电商平台

来源:互联网 发布:linux 外网时间服务器 编辑:程序博客网 时间:2024/05/16 16:20

CK2040-Spring高效开发带前后端开发完整电商平台

随笔背景:在很多时候,很多入门不久的朋友都会问我:我是从其他语言转到程序开发的,有没有一些基础性的资料给我们学习学习呢,你的框架感觉一下太大了,希望有个循序渐进的教程或者视频来学习就好了。对于学习有困难不知道如何提升自己可以加扣:1225462853进行交流得到帮助,获取学习资料.

CK2040-Spring高效开发带前后端开发完整电商平台

下载地址:http://pan.baidu.com/s/1jI05TPW

实例工厂实例化 – 工厂方法模式

<!-- 第三种使用实例工厂实例化 --><bean id="bean3" factory-bean="bean3Factory" factory-method="getBean3"></bean><bean id="bean3Factory" class="cn.itcast.spring3.demo2.Bean3Factory"/>public class PersonServiceFactory {    public  PersonService  createPersonService(){        return new PersonServiceImpl();       }}

/** * Bean的实例化的测试 *  * @author ppl *  */public class SpringTest2 {    @Test    // 无参数的构造方法的实例化    public void demo1() {        ApplicationContext applicationContext = new ClassPathXmlApplicationContext(                "applicationContext.xml");        Bean1 bean1 = (Bean1) applicationContext.getBean("bean1");        System.out.println(bean1);    }    @Test    // 静态工厂实例化    public void demo2() {        ApplicationContext applicationContext = new ClassPathXmlApplicationContext(                "applicationContext.xml");        Bean2 bean2 = (Bean2) applicationContext.getBean("bean2");        System.out.println(bean2);    }    @Test    // 实例工厂实例化    public void demo3() {        ApplicationContext applicationContext = new ClassPathXmlApplicationContext(                "applicationContext.xml");        Bean3 bean3 = (Bean3) applicationContext.getBean("bean3");        System.out.println(bean3);    }

Bean的其他配置

Bean的命名 id属性和name属性

一般情况下,装配一个Bean时,通过指定一个id属性作为Bean的名称
id 属性在IoC容器中必须是唯一的
id 的命名要满足XML对ID属性命名规范 
id遵守XML约束的id的约束.id约束保证这个属性的值是唯一的,而且必须以字母开始,可以使用字母、数字、连字符、下划线、句话、冒号
如果Bean的名称中含有特殊字符,就需要使用name属性
例如: 
<bean name="#person" class="cn.itcast.bean.Person"/>
因为name属性可以相同,所以后出现Bean会覆盖之前出现的同名的Bean