This commit is contained in:
xuchengsheng 2023-09-15 14:44:51 +08:00
commit 9620307996
63 changed files with 1053 additions and 0 deletions

33
.gitignore vendored Normal file
View File

@ -0,0 +1,33 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/

65
pom.xml Normal file
View File

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<groupId>com.xcs.spring</groupId>
<artifactId>spring-reading</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-reading</name>
<description>spring-reading</description>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<java.version>11</java.version>
<spring.version>5.3.10</spring.version>
</properties>
<modules>
<module>spring-interface-beanFactoryPostProcessor</module>
<module>spring-interface-beanPostProcessor</module>
<module>spring-interface-environment</module>
<module>spring-interface-applicationListener</module>
<module>spring-interface-importSelector</module>
<module>spring-interface-importBeanDefinitionRegistrar</module>
<module>spring-interface-resource</module>
<module>spring-interface-embeddedValueResolver</module>
<module>spring-interface-factoryBean</module>
<module>spring-annotation-configuration</module>
<module>spring-annotation-bean</module>
<module>spring-annotation-import</module>
<module>spring-annotation-propertySource</module>
<module>spring-annotation-componentScan</module>
</modules>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>spring-reading</artifactId>
<groupId>com.xcs.spring</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-annotation-bean</artifactId>
</project>

View File

@ -0,0 +1,19 @@
package com.xcs.spring;
import com.xcs.spring.config.MyBeanConfig;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
/**
* @author xcs
* @date 2023年08月07日 16时21分
**/
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);
}
context.close();
}
}

View File

@ -0,0 +1,9 @@
package com.xcs.spring.bean;
/**
* @author 林雷
* @date 2023年08月23日 15时30分
**/
public class A {
}

View File

@ -0,0 +1,14 @@
package com.xcs.spring.bean;
/**
* @author 林雷
* @date 2023年08月23日 15时30分
**/
public class B {
private A a;
public B(A a) {
this.a = a;
}
}

View File

@ -0,0 +1,22 @@
package com.xcs.spring.bean;
/**
* @author 林雷
* @date 2023年08月25日 10时22分
**/
public class MyBean {
private String name;
public MyBean(String name) {
this.name = name;
}
public void init(){
System.out.println("MyBean.init");
}
public void destroy(){
System.out.println("MyBean.destroy");
}
}

View File

@ -0,0 +1,30 @@
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.Configuration;
/**
* @author xcs
* @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());
}
@Bean(initMethod = "init",destroyMethod = "destroy")
public MyBean myBean(){
return new MyBean("xcs");
}
}

View File

@ -0,0 +1,11 @@
package com.xcs.spring.service;
import org.springframework.stereotype.Service;
/**
* @author 林雷
* @date 2023年08月14日 17时14分
**/
@Service
public class MyService1 {
}

View File

@ -0,0 +1,12 @@
package com.xcs.spring.service;
import org.springframework.stereotype.Service;
/**
* @author 林雷
* @date 2023年08月14日 17时14分
**/
@Service
public class MyService2 {
}

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>spring-reading</artifactId>
<groupId>com.xcs.spring</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-annotation-componentScan</artifactId>
</project>

View File

@ -0,0 +1,18 @@
package com.xcs.spring;
import com.xcs.spring.config.MyComponentScanConfig;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
/**
* @author xcs
* @date 2023年08月07日 16时21分
**/
public class ComponentScanApplication {
public static void main(String[] args) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyComponentScanConfig.class);
for (String beanDefinitionName : context.getBeanDefinitionNames()) {
System.out.println("beanName = " + beanDefinitionName);
}
}
}

View File

@ -0,0 +1,8 @@
package com.xcs.spring;
/**
* @author 林雷
* @date 2023年08月14日 15时06分
**/
public class MyPackageMarker {
}

View File

@ -0,0 +1,12 @@
package com.xcs.spring.component;
import org.springframework.stereotype.Component;
import java.lang.annotation.*;
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface MyAnnotation {
}

View File

@ -0,0 +1,12 @@
package com.xcs.spring.component;
import org.springframework.stereotype.Component;
/**
* @author 林雷
* @date 2023年08月15日 14时13分
**/
@Component
public class MyComponent implements MyInterface {
}

View File

@ -0,0 +1,9 @@
package com.xcs.spring.component;
/**
* @author 林雷
* @date 2023年08月16日 15时46分
**/
@MyAnnotation
public class MyComponentAnnotation {
}

View File

@ -0,0 +1,12 @@
package com.xcs.spring.component;
import org.springframework.stereotype.Component;
/**
* @author 林雷
* @date 2023年08月15日 15时04分
**/
@Component
public class MyComponentAspectJ {
}

View File

@ -0,0 +1,12 @@
package com.xcs.spring.component;
import org.springframework.stereotype.Component;
/**
* @author 林雷
* @date 2023年08月15日 14时15分
**/
@Component
public class MyComponentCustom {
}

View File

@ -0,0 +1,11 @@
package com.xcs.spring.component;
import org.springframework.stereotype.Component;
/**
* @author 林雷
* @date 2023年08月15日 14时59分
**/
@Component
public class MyComponentRegex {
}

View File

@ -0,0 +1,8 @@
package com.xcs.spring.component;
/**
* @author 林雷
* @date 2023年08月15日 14时12分
**/
public interface MyInterface {
}

View File

@ -0,0 +1,43 @@
package com.xcs.spring.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
/**
* @author xcs
* @date 2023年08月07日 16时25分
**/
@Configuration
@ComponentScan(basePackages = "com.xcs.spring")
// includeFilters 基于ANNOTATION过滤
// @ComponentScan(includeFilters = @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = Service.class), useDefaultFilters = false)
// includeFilters 基于ASSIGNABLE_TYPE过滤
// @ComponentScan(includeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = MyInterface.class), useDefaultFilters = false)
// includeFilters 基于CUSTOM过滤
// @ComponentScan(includeFilters = @ComponentScan.Filter(type = FilterType.CUSTOM, classes = MyCustomTypeFilter.class), useDefaultFilters = false)
// includeFilters 基于REGEX过滤
// @ComponentScan(includeFilters = @ComponentScan.Filter(type = FilterType.REGEX, pattern = ".*ComponentRegex"), useDefaultFilters = false)
// includeFilters 基于AspectJ过滤
// @ComponentScan(includeFilters = @ComponentScan.Filter(type = FilterType.ASPECTJ, pattern = "*..*AspectJ"), useDefaultFilters = false)
// excludeFilters 基于ANNOTATION过滤
// @ComponentScan(excludeFilters = @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = Service.class))
// excludeFilters 基于ASSIGNABLE_TYPE过滤
// @ComponentScan(excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = MyInterface.class))
// excludeFilters 基于CUSTOM过滤
// @ComponentScan(excludeFilters = @ComponentScan.Filter(type = FilterType.CUSTOM, classes = MyCustomTypeFilter.class))
// excludeFilters 基于REGEX过滤
// @ComponentScan(excludeFilters = @ComponentScan.Filter(type = FilterType.REGEX, pattern = ".*ComponentRegex"))
// excludeFilters 基于AspectJ过滤
// @ComponentScan(excludeFilters = @ComponentScan.Filter(type = FilterType.ASPECTJ, pattern = "*..*AspectJ"))
public class MyComponentScanConfig {
}

View File

@ -0,0 +1,24 @@
package com.xcs.spring.config;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;
/**
* @author 林雷
* @date 2023年08月14日 15时38分
**/
public class MyCustomBeanNameGenerator implements BeanNameGenerator {
@Override
public String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) {
// 此处只是一个示例我们可以根据自己的实际情况生成Bean名称
String originalName = definition.getBeanClassName();
if (originalName != null) {
return "_这是我自定义Bean名称的前缀_" + originalName;
} else {
// 你可以选择其他的逻辑处理或者抛出异常
throw new IllegalArgumentException("Bean class name is null");
}
}
}

View File

@ -0,0 +1,31 @@
package com.xcs.spring.config;
import com.xcs.spring.service.MyService1;
import com.xcs.spring.service.MyService2;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.AnnotationScopeMetadataResolver;
import org.springframework.context.annotation.ScopeMetadata;
import org.springframework.context.annotation.ScopeMetadataResolver;
/**
* @author 林雷
* @date 2023年08月14日 17时07分
**/
public class MyCustomScopeMetadataResolver implements ScopeMetadataResolver {
private AnnotationScopeMetadataResolver resolver = new AnnotationScopeMetadataResolver();
@Override
public ScopeMetadata resolveScopeMetadata(BeanDefinition definition) {
ScopeMetadata scopeMetadata = new ScopeMetadata();
// 检查Bean的名称是否为'MyService1'或'MyService2'并据此设置相应的作用域
if (MyService1.class.getName().equals(definition.getBeanClassName()) ||
MyService2.class.getName().equals(definition.getBeanClassName())) {
scopeMetadata.setScopeName(BeanDefinition.SCOPE_PROTOTYPE);
return scopeMetadata;
}
// 再次交由AnnotationScopeMetadataResolver解析否则会导致@Scope失效
return resolver.resolveScopeMetadata(definition);
}
}

View File

@ -0,0 +1,11 @@
package com.xcs.spring.controller;
import org.springframework.stereotype.Controller;
/**
* @author 林雷
* @date 2023年08月14日 17时14分
**/
@Controller
public class MyController1 {
}

View File

@ -0,0 +1,11 @@
package com.xcs.spring.controller;
import org.springframework.stereotype.Controller;
/**
* @author 林雷
* @date 2023年08月14日 17时14分
**/
@Controller
public class MyController2 {
}

View File

@ -0,0 +1,18 @@
package com.xcs.spring.filter;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;
import java.io.IOException;
/**
* @author 林雷
* @date 2023年08月15日 14时15分
**/
public class MyCustomTypeFilter implements TypeFilter {
@Override
public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {
return metadataReader.getClassMetadata().getClassName().endsWith("Custom");
}
}

View File

@ -0,0 +1,11 @@
package com.xcs.spring.service;
import org.springframework.stereotype.Service;
/**
* @author 林雷
* @date 2023年08月14日 17时14分
**/
@Service
public class MyService1 {
}

View File

@ -0,0 +1,11 @@
package com.xcs.spring.service;
import org.springframework.stereotype.Service;
/**
* @author 林雷
* @date 2023年08月14日 17时14分
**/
@Service
public class MyService2 {
}

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>spring-reading</artifactId>
<groupId>com.xcs.spring</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-annotation-configuration</artifactId>
</project>

View File

@ -0,0 +1,28 @@
package com.xcs.spring;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import java.io.IOException;
/**
* @author xcs
* @date 2023年08月07日 16时21分
**/
public class ConfigurationApplication {
public static void main(String[] args) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyConfiguration.class);
MyConfiguration configuration = context.getBean(MyConfiguration.class);
System.out.println(configuration.myBean());
System.out.println(configuration.myBean());
System.out.println("MyConfiguration = " + configuration.getClass().getName());
try {
System.in.read();
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,18 @@
package com.xcs.spring;
import com.xcs.spring.bean.MyBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author xcs
* @date 2023年08月07日 16时25分
**/
@Configuration
public class MyConfiguration {
@Bean
public MyBean myBean(){
return new MyBean();
}
}

View File

@ -0,0 +1,18 @@
package com.xcs.spring.bean;
/**
* @author xcs
* @date 2023年08月07日 16时26分
**/
public class MyBean {
private String beanId;
public String getBeanId() {
return beanId;
}
public void setBeanId(String beanId) {
this.beanId = beanId;
}
}

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>spring-reading</artifactId>
<groupId>com.xcs.spring</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-annotation-import</artifactId>
</project>

View File

@ -0,0 +1,18 @@
package com.xcs.spring;
import com.xcs.spring.config.MyConfig;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
/**
* @author xcs
* @date 2023年08月07日 16时21分
**/
public class ImportApplication {
public static void main(String[] args) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyConfig.class);
for (String beanDefinitionName : context.getBeanDefinitionNames()) {
System.out.println("beanName = " + beanDefinitionName);
}
}
}

View File

@ -0,0 +1,21 @@
package com.xcs.spring.bean;
/**
* @author 林雷
* @date 2023年09月11日 11时13分
**/
public class MyBean {
private String describe;
public MyBean(String describe) {
this.describe = describe;
}
@Override
public String toString() {
return "MyBean{" +
"describe='" + describe + '\'' +
'}';
}
}

View File

@ -0,0 +1,8 @@
package com.xcs.spring.bean;
/**
* @author 林雷
* @date 2023年08月28日 11时13分
**/
public class MyBeanA {
}

View File

@ -0,0 +1,8 @@
package com.xcs.spring.bean;
/**
* @author 林雷
* @date 2023年08月28日 11时13分
**/
public class MyBeanB {
}

View File

@ -0,0 +1,8 @@
package com.xcs.spring.bean;
/**
* @author 林雷
* @date 2023年08月28日 11时13分
**/
public class MyBeanC {
}

View File

@ -0,0 +1,8 @@
package com.xcs.spring.bean;
/**
* @author 林雷
* @date 2023年08月28日 11时13分
**/
public class MyBeanD {
}

View File

@ -0,0 +1,14 @@
package com.xcs.spring.bean;
/**
* @author 林雷
* @date 2023年08月28日 10时48分
**/
public class User {
private String name;
public User(String name) {
this.name = name;
}
}

View File

@ -0,0 +1,18 @@
package com.xcs.spring.config;
import com.xcs.spring.bean.MyBeanA;
import com.xcs.spring.bean.MyBeanC;
import org.springframework.context.annotation.DeferredImportSelector;
import org.springframework.core.type.AnnotationMetadata;
/**
* @author 林雷
* @date 2023年08月29日 11时08分
**/
public class CustomDeferredImportSelector implements DeferredImportSelector {
@Override
public String[] selectImports(AnnotationMetadata importingClassMetadata) {
return new String[]{MyBeanC.class.getName()};
}
}

View File

@ -0,0 +1,16 @@
package com.xcs.spring.config;
import com.xcs.spring.bean.MyBeanA;
import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;
/**
* @author 林雷
* @date 2023年08月28日 11时12分
**/
public class CustomImportSelector implements ImportSelector {
@Override
public String[] selectImports(AnnotationMetadata importingClassMetadata) {
return new String[]{MyBeanA.class.getName()};
}
}

View File

@ -0,0 +1,19 @@
package com.xcs.spring.config;
import com.xcs.spring.bean.MyBeanB;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;
/**
* @author 林雷
* @date 2023年08月28日 11时17分
**/
public class CustomRegistrar implements ImportBeanDefinitionRegistrar {
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
RootBeanDefinition beanDefinition = new RootBeanDefinition(MyBeanB.class);
registry.registerBeanDefinition("myBeanB", beanDefinition);
}
}

View File

@ -0,0 +1,27 @@
package com.xcs.spring.config;
import com.xcs.spring.service.MyService;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
* @author xcs
* @date 2023年08月07日 16时25分
**/
@Configuration
// 导入常规的 @Configuration
// @Import(UserConfig.class)
// 导入普通的组件类
// @Import(MyService.class)
// 使用ImportSelector
// @Import(CustomImportSelector.class)
// 使用 ImportBeanDefinitionRegistrar
// @Import(CustomRegistrar.class)
@Import({UserConfig.class, MyService.class, CustomImportSelector.class, CustomDeferredImportSelector.class, CustomRegistrar.class})
public class MyConfig {
}

View File

@ -0,0 +1,18 @@
package com.xcs.spring.config;
import com.xcs.spring.bean.User;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author 林雷
* @date 2023年08月28日 10时48分
**/
@Configuration
public class UserConfig {
@Bean
public User user(){
return new User("xcs");
}
}

View File

@ -0,0 +1,20 @@
package com.xcs.spring.service;
import com.xcs.spring.bean.MyBeanD;
import org.springframework.context.annotation.Bean;
/**
* @author 林雷
* @date 2023年08月28日 11时00分
**/
public class MyService {
@Bean
public MyBeanD myBeanD(){
return new MyBeanD();
}
public String getInfo(){
return "MyService info";
}
}

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>spring-reading</artifactId>
<groupId>com.xcs.spring</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-annotation-propertySource</artifactId>
</project>

View File

@ -0,0 +1,17 @@
package com.xcs.spring;
import com.xcs.spring.config.MyBeanConfig;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
/**
* @author xcs
* @date 2023年08月07日 16时21分
**/
public class PropertySourceApplication {
public static void main(String[] args) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyBeanConfig.class);
System.out.println("apiVersion = " + context.getEnvironment().getProperty("apiVersion"));
System.out.println("kind = " + context.getEnvironment().getProperty("kind"));
}
}

View File

@ -0,0 +1,14 @@
package com.xcs.spring.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
/**
* @author xcs
* @date 2023年08月07日 16时25分
**/
@Configuration
@PropertySource("classpath:my-application.yml")
public class MyBeanConfig {
}

View File

@ -0,0 +1,2 @@
apiVersion: v1
kind: ConfigMap

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>spring-reading</artifactId>
<groupId>com.xcs.spring</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-interface-applicationListener</artifactId>
</project>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>spring-reading</artifactId>
<groupId>com.xcs.spring</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-interface-beanFactoryPostProcessor</artifactId>
</project>

View File

@ -0,0 +1,22 @@
package com.xcs.spring;
import com.xcs.spring.config.MyConfiguration;
import com.xcs.spring.config.MySimpleBean;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
/**
* @author xcs
* @date 2023年08月07日 16时21分
**/
public class BeanFactoryPostProcessorApplication {
public static void main(String[] args) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyConfiguration.class);
MySimpleBean mySimpleBean1 = context.getBean(MySimpleBean.class);
MySimpleBean mySimpleBean2 = context.getBean(MySimpleBean.class);
mySimpleBean1.show();
mySimpleBean2.show();
}
}

View File

@ -0,0 +1,22 @@
package com.xcs.spring.config;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
/**
* @author 林雷
* @date 2023年09月14日 14时17分
**/
public class MyBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
System.out.println("修改bean的定义");
BeanDefinition beanDefinition = beanFactory.getBeanDefinition("mySimpleBean");
beanDefinition.setScope(BeanDefinition.SCOPE_PROTOTYPE);
System.out.println("将mySimpleBean从默认的单例修改成多例");
System.out.println("修改bean的定义已完成");
}
}

View File

@ -0,0 +1,23 @@
package com.xcs.spring.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
/**
* @author xcs
* @date 2023年08月07日 16时25分
**/
@Configuration
public class MyConfiguration {
@Bean
public MySimpleBean mySimpleBean(){
return new MySimpleBean();
}
@Bean
public MyBeanFactoryPostProcessor myBeanFactoryPostProcessor(){
return new MyBeanFactoryPostProcessor();
}
}

View File

@ -0,0 +1,12 @@
package com.xcs.spring.config;
/**
* @author 林雷
* @date 2023年09月14日 16时05分
**/
public class MySimpleBean {
public void show() {
System.out.println("MySimpleBean instance: " + this);
}
}

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>spring-reading</artifactId>
<groupId>com.xcs.spring</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-interface-beanPostProcessor</artifactId>
</project>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>spring-reading</artifactId>
<groupId>com.xcs.spring</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-interface-embeddedValueResolver</artifactId>
</project>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>spring-reading</artifactId>
<groupId>com.xcs.spring</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-interface-environment</artifactId>
</project>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>spring-reading</artifactId>
<groupId>com.xcs.spring</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-interface-factoryBean</artifactId>
</project>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>spring-reading</artifactId>
<groupId>com.xcs.spring</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-interface-importBeanDefinitionRegistrar</artifactId>
</project>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>spring-reading</artifactId>
<groupId>com.xcs.spring</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-interface-importSelector</artifactId>
</project>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>spring-reading</artifactId>
<groupId>com.xcs.spring</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-interface-resource</artifactId>
</project>