@Bean源码分析
parent
c56de63752
commit
fbd7363d25
10
README.md
10
README.md
|
@ -70,15 +70,15 @@
|
|||
+ 关于ServletConfigAware源码分析
|
||||
+ 关于ServletContextAware源码分析
|
||||
+ 关于EnvironmentAware源码分析
|
||||
+ 核心注解
|
||||
|
||||
+ 关于@Bean源码分析
|
||||
+ 核心注解
|
||||
+ [关于@Bean源码分析](spring-annotation-bean/README.md)
|
||||
+ 关于@ComponentScan源码分析
|
||||
+ 关于@Configuration源码分析
|
||||
+ 关于@Import源码分析
|
||||
+ 关于@PropertySource源码分析
|
||||
+ Bean生命周期和工厂
|
||||
|
||||
+ 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
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
package com.xcs.spring.bean;
|
||||
|
||||
/**
|
||||
* @author xcs
|
||||
* @date 2023年08月23日 15时30分
|
||||
**/
|
||||
public class A {
|
||||
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package com.xcs.spring.bean;
|
||||
|
||||
/**
|
||||
* @author xcs
|
||||
* @date 2023年08月23日 15时30分
|
||||
**/
|
||||
public class B {
|
||||
|
||||
private A a;
|
||||
|
||||
public B(A a) {
|
||||
this.a = a;
|
||||
}
|
||||
}
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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 2023年08月07日 16时25分
|
||||
**/
|
||||
@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();
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package com.xcs.spring.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author xcs
|
||||
* @date 2023年08月14日 17时14分
|
||||
**/
|
||||
@Service
|
||||
public class MyService1 {
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
package com.xcs.spring.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author xcs
|
||||
* @date 2023年08月14日 17时14分
|
||||
**/
|
||||
@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
Loading…
Reference in New Issue