@Bean源码分析

master
xuchengsheng 2023-09-27 17:50:26 +08:00
parent c56de63752
commit fbd7363d25
13 changed files with 5662 additions and 76 deletions

View File

@ -70,15 +70,15 @@
+ 关于ServletConfigAware源码分析
+ 关于ServletContextAware源码分析
+ 关于EnvironmentAware源码分析
+ 核心注解
+ 关于@Bean源码分析
+ 核心注解
+ [关于@Bean源码分析](spring-annotation-bean/README.md)
+ 关于@ComponentScan源码分析
+ 关于@Configuration源码分析
+ 关于@Import源码分析
+ 关于@PropertySource源码分析
+ Bean生命周期和工厂
+ 关于BeanFactory源码分析
+ 关于HierarchicalBeanFactory源码分析
+ 关于ListableBeanFactory源码分析
@ -88,15 +88,15 @@
+ 关于BeanDefinition源码分析
+ 关于BeanDefinitionRegistry源码分析
+ 关于FactoryBean源码分析
+ 应用上下文相
+ 应用上下文相
- 关于ApplicationContext源码分析
- 关于ConfigurableApplicationContext源码分析
- 关于WebApplicationContext源码分析
- 关于ApplicationEventPublisher源码分析
- 关于ApplicationListener源码分析
+ 环境变量
- 关于Environment源码分析
- 关于PropertyResolver源码分析
- 关于PropertySources源码分析

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,7 @@
package com.xcs.spring;
import com.xcs.spring.config.MyBeanConfig;
import com.xcs.spring.bean.MyBean;
import com.xcs.spring.config.MyConfiguration;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
/**
@ -10,10 +11,8 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
public class BeanApplication {
public static void main(String[] args) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyBeanConfig.class);
for (String beanDefinitionName : context.getBeanDefinitionNames()) {
System.out.println("beanName = " + beanDefinitionName);
}
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyConfiguration.class);
System.out.println(context.getBean(MyBean.class));
context.close();
}
}

View File

@ -1,9 +0,0 @@
package com.xcs.spring.bean;
/**
* @author xcs
* @date 20230823 1530
**/
public class A {
}

View File

@ -1,14 +0,0 @@
package com.xcs.spring.bean;
/**
* @author xcs
* @date 20230823 1530
**/
public class B {
private A a;
public B(A a) {
this.a = a;
}
}

View File

@ -6,12 +6,6 @@ package com.xcs.spring.bean;
**/
public class MyBean {
private String name;
public MyBean(String name) {
this.name = name;
}
public void init(){
System.out.println("MyBean.init");
}

View File

@ -1,9 +1,8 @@
package com.xcs.spring.config;
import com.xcs.spring.bean.A;
import com.xcs.spring.bean.B;
import com.xcs.spring.bean.MyBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
/**
@ -11,20 +10,10 @@ import org.springframework.context.annotation.Configuration;
* @date 20230807 1625
**/
@Configuration
public class MyBeanConfig {
@Bean
public A a(){
return new A();
}
@Bean
public B b(){
return new B(a());
}
public class MyConfiguration {
@Bean(initMethod = "init",destroyMethod = "destroy")
public MyBean myBean(){
return new MyBean("xcs");
return new MyBean();
}
}

View File

@ -1,11 +0,0 @@
package com.xcs.spring.service;
import org.springframework.stereotype.Service;
/**
* @author xcs
* @date 20230814 1714
**/
@Service
public class MyService1 {
}

View File

@ -1,12 +0,0 @@
package com.xcs.spring.service;
import org.springframework.stereotype.Service;
/**
* @author xcs
* @date 20230814 1714
**/
@Service
public class MyService2 {
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff