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/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd">
<bean id=“eb1”
class=“container.instantiation.ExampleBean”/>
<bean id=“cal1” class=“java.util.Calendar”
factory-method=“getInstance”/>
<bean id=“cal2”
class=“java.util.GregorianCalendar”/>
<bean id=“time1” factory-bean=“cal2”
factory-method=“getTime”/>
StartSping.java
package container.first;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class StartSping {
public static void main(String[] args) {
//启动spring容器(配置文件名不区分大小写)
ApplicationContext ac = new ClassPathXmlApplicationContext(“applicationcontext.xml”);
System.out.println(ac);
}
}
运行程序后,后台执行结果:
演示 创建对象的方式:
ExampleBean.java
package container.instantiation;
public class ExampleBean {
public ExampleBean() {
System.out.println(“ExamleBean的无参构造器…”);
}
}
TestCase.java
package test;
import java.util.Calendar;
import java.util.Date;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import container.instantiation.ExampleBean;
public class TestCase {
@Test
//测试容器创建对象的第一种方式(调用无参构造器)
public void test1(){
//启动容器
ApplicationContext ac = new ClassPathXmlApplicationContext(“applicationcontext.xml”);
System.out.println(ac);
//向容器申请获得一个对象
ExampleBean eb1 = ac.getBean(“eb1”, ExampleBean.class);
System.out.println(eb1);
Date date1 = ac.getBean(“date1”, Date.class);
System.out.println(date1);
}
@Test
//测试容器创建对象的第二种方式(静态工厂方法)
public void test2(){
//启动容器
ApplicationContext ac = new ClassPathXmlApplicationContext(“applicationContext.xml”);
System.out.println(ac);
Calendar cal = ac.getBean(“cal1”, Calendar.class);
System.out.println(cal);
}
@Test
//测试容器创建对象的第三种方式(实例工厂方法)
public void test3(){
//启动容器
ApplicationContext ac = new ClassPathXmlApplicationContext(“applicationContext.xml”);
System.out.println(ac);
Date date = ac.getBean(“time1”, Date.class);
System.out.println(date);
}
}
依次运行test1,test2,test3,后台运行结果:
A.
B.
C.
生命周期的管理、作用域、延迟加载****演示
MessageBean.java
package container.life;
public class MessageBean {
public MessageBean(){
System.out.println(“MessageBean的无参构造器…”);
}
public void init(){
System.out.println(“init方法…”);
}
public void sendMsg(){
System.out.println(“发送消息…”);
}
public void destroy(){
System.out.println(“destroy方法…”);
}
}
SomeBean.java
package container.life;
public class SomeBean {
public SomeBean(){
System.out.println(“SomeBean的无参构造器…”);
}
}
app2.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: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:aop=“http://www.springframework.org/schema/aop”
xmlns:mvc=“http://www.springframework.org/schema/mvc”
xmlns:util=“http://www.springframework.org/schema/util”
xmlns:jpa=“http://www.springframework.org/schema/data/jpa”
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/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd">
<bean id=“mb1”
class=“container.life.MessageBean”
init-method=“init”
destroy-method=“destroy”
scope=“prototype”>
<bean id=“sb1” class=“container.life.SomeBean”
scope=“prototype”>
<bean id=“sb2” class=“container.life.SomeBean”
lazy-init=“true”>
TestCae2.java
package test;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import container.life.MessageBean;
import container.life.SomeBean;
public class TestCae2 {
@Test
//测试生命周期相关的几个
public void test1(){
//关闭容器的方法在ApplicationContext
//接口当中没有提供,需要使用其子接口
//AbstractApplicationContext
AbstractApplicationContext ac = new ClassPathXmlApplicationContext(“app2.xml”);
MessageBean mb = ac.getBean(“mb1”,MessageBean.class);
mb.sendMsg();
System.out.println(mb);
ac.close();
}
@Test
//测试作用域
public void test2(){
ApplicationContext ac = new ClassPathXmlApplicationContext(“app2.xml”);
SomeBean sb1 = ac.getBean(“sb1”, SomeBean.class);
SomeBean sb2 = ac.getBean(“sb1”, SomeBean.class);
System.out.println(sb1 == sb2);
}
@Test
//测试作用域 (lazy-init)
public void test3(){
ApplicationContext ac = new ClassPathXmlApplicationContext(“app2.xml”);
SomeBean sb2= ac.getBean(“sb2”, SomeBean.class);
}
}
依次运行test1、test2、test3,运行结果如下
A.
B.
C:
没有getBean获取对象时不会创建对象:
IOC(Inversion Of Controll 控制反转) 演示
app3.xml
<?xml version="1.0" encoding="UTF-8"?>小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级Java工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年最新Java开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Java)
最后
经过日积月累, 以下是小编归纳整理的深入了解Java虚拟机文档,希望可以帮助大家过关斩将顺利通过面试。
由于整个文档比较全面,内容比较多,篇幅不允许,下面以截图方式展示 。
由于篇幅限制,文档的详解资料太全面,细节内容太多,所以只把部分知识点截图出来粗略的介绍,每个小节点里面都有更细化的内容!
[外链图片转存中…(img-ZX3tcmbu-1711174017673)]
[外链图片转存中…(img-SBhTOzGp-1711174017674)]
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Java)
[外链图片转存中…(img-2KBb5XQO-1711174017675)]
最后
经过日积月累, 以下是小编归纳整理的深入了解Java虚拟机文档,希望可以帮助大家过关斩将顺利通过面试。
由于整个文档比较全面,内容比较多,篇幅不允许,下面以截图方式展示 。
[外链图片转存中…(img-osvYF6kc-1711174017675)]
[外链图片转存中…(img-VcmIZUuT-1711174017676)]
[外链图片转存中…(img-s0XI26ud-1711174017676)]
[外链图片转存中…(img-WOO5ajqF-1711174017677)]
[外链图片转存中…(img-ucqKGjex-1711174017677)]
[外链图片转存中…(img-vNQnzWCS-1711174017678)]
[外链图片转存中…(img-bS1mkPr0-1711174017678)]
由于篇幅限制,文档的详解资料太全面,细节内容太多,所以只把部分知识点截图出来粗略的介绍,每个小节点里面都有更细化的内容!