diff --git a/SpringFramework-Lifecycle/pom.xml b/SpringFramework-Lifecycle/pom.xml new file mode 100644 index 0000000..cba5018 --- /dev/null +++ b/SpringFramework-Lifecycle/pom.xml @@ -0,0 +1,20 @@ + + + 4.0.0 + + com.linlangjz + SpringStudy + 1.0-SNAPSHOT + + + SpringFramework-Lifecycle + + + + org.springframework + spring-context + + + \ No newline at end of file diff --git a/SpringFramework-Lifecycle/src/main/java/com/ycjy/LifecycleDemo.java b/SpringFramework-Lifecycle/src/main/java/com/ycjy/LifecycleDemo.java new file mode 100644 index 0000000..c0826af --- /dev/null +++ b/SpringFramework-Lifecycle/src/main/java/com/ycjy/LifecycleDemo.java @@ -0,0 +1,47 @@ +package com.ycjy; + +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.BeanFactoryAware; +import org.springframework.beans.factory.DisposableBean; +import org.springframework.beans.factory.InitializingBean; + +public class LifecycleDemo implements BeanFactoryAware, InitializingBean, DisposableBean { + + @Override + public void setBeanFactory(BeanFactory beanFactory) throws BeansException { + System.out.println("111" + beanFactory); + } + + @Override + public void destroy() throws Exception { + System.out.println("--destroy捣毁, 销毁"); + } + public void xiaohui() { + System.out.println("--xiaohui销毁"); + } + + private String p1; + private String p2; + + public void setP1(String p1) { + System.out.println("装配属性p1"); + this.p1 = p1; + } + + public void setP2(String p2) { + System.out.println("装配属性p2"); + this.p2 = p2; + } + + @Override + public void afterPropertiesSet() throws Exception { + System.out.println("--afterPropertiesSet属性设置之后"); + } + + public void init() { + System.out.println("初始化init"); + System.out.println("--p1 " + p1); + System.out.println("--p2 " + p2); + } +} \ No newline at end of file diff --git a/SpringFramework-Lifecycle/src/main/java/com/ycjy/Main.java b/SpringFramework-Lifecycle/src/main/java/com/ycjy/Main.java new file mode 100644 index 0000000..1354c35 --- /dev/null +++ b/SpringFramework-Lifecycle/src/main/java/com/ycjy/Main.java @@ -0,0 +1,11 @@ +package com.ycjy; + +import org.springframework.context.support.ClassPathXmlApplicationContext; + +public class Main { + public static void main(String[] args) { + ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); + context.getBean("lifecycle", LifecycleDemo.class); + context.close();// 上下文关闭 + } +} \ No newline at end of file diff --git a/SpringFramework-Lifecycle/src/main/resources/applicationContext.xml b/SpringFramework-Lifecycle/src/main/resources/applicationContext.xml new file mode 100644 index 0000000..bd760d6 --- /dev/null +++ b/SpringFramework-Lifecycle/src/main/resources/applicationContext.xml @@ -0,0 +1,15 @@ + + + + + + + + \ No newline at end of file