├── springboot-conditional ├── src │ ├── main │ │ ├── resources │ │ │ ├── mybatis.xml │ │ │ ├── application-dev.yml │ │ │ ├── application-prod.yml │ │ │ ├── application.yml │ │ │ └── import.xml │ │ └── java │ │ │ └── spring │ │ │ └── study │ │ │ └── conditional │ │ │ ├── bean │ │ │ ├── ConditionNoneBean.java │ │ │ ├── ConditionResourceBean.java │ │ │ ├── ConditionExpressionBean.java │ │ │ ├── ConditionClassBean.java │ │ │ ├── ConditionBeanBean.java │ │ │ └── MyConditionalBean.java │ │ │ ├── condition │ │ │ ├── ConditionBeanInXml.java │ │ │ ├── ConditionBeanWithComponent.java │ │ │ └── ConditionBeanInImport.java │ │ │ └── ConditionalApplication.java │ └── test │ │ └── java │ │ └── spring │ │ └── study │ │ └── conditional │ │ └── test │ │ └── TestConditionReport.java └── pom.xml ├── springboot-factories-loader ├── src │ ├── main │ │ ├── resources │ │ │ └── application.yml │ │ └── java │ │ │ └── spring │ │ │ └── study │ │ │ └── factories │ │ │ └── loader │ │ │ └── SpringFactoriesApplication.java │ └── test │ │ └── java │ │ └── spring │ │ └── study │ │ └── factories │ │ └── loader │ │ └── test │ │ └── LoadTest.java └── pom.xml ├── spring-bean-post-processor ├── src │ └── main │ │ ├── resources │ │ ├── application.yaml │ │ └── rebel.xml │ │ └── java │ │ └── spring │ │ └── study │ │ └── beanpostproessor │ │ ├── bean │ │ ├── ISimpleService.java │ │ ├── SimpleServiceForMerged.java │ │ ├── ReferenceA.java │ │ ├── SimpleServiceForDestroy.java │ │ ├── EmbeddedService.java │ │ ├── ReferenceB.java │ │ ├── SimpleServiceForSmart.java │ │ └── SimpleServiceImpl.java │ │ ├── embedded │ │ ├── BeanForAop.java │ │ ├── BeanForSchedule.java │ │ ├── BeanForAsync.java │ │ ├── BeanForBeanValidation.java │ │ ├── BeanForMethodValidation.java │ │ ├── BeanForAutowired.java │ │ ├── BeanForRequired.java │ │ └── BeanForCommon.java │ │ ├── aop │ │ └── MyAspect.java │ │ ├── registrar │ │ └── SimpleRegistrar.java │ │ ├── processor │ │ ├── SimpleBeanPostProcessor.java │ │ ├── SimpleDestructionAwareBeanPostProcessor.java │ │ ├── SimpleMergedBeanDefinitionPostProcessor.java │ │ ├── SimpleInstantiationAwareBeanPostProcessor.java │ │ └── SimpleSmartInstantiationAwareBeanPostProcessor.java │ │ ├── runner │ │ └── SimpleCommandLineRunner.java │ │ └── BeanPostProcessorApplication.java └── pom.xml ├── springboot-embedded-servlet-conatiner ├── src │ └── main │ │ ├── resources │ │ ├── static │ │ │ └── 404.html │ │ ├── templates │ │ │ └── error.ftl.1 │ │ └── application.yml │ │ └── java │ │ └── spring │ │ └── study │ │ └── embedded │ │ └── servlet │ │ ├── EmbeddedServletApplication.java │ │ ├── listener │ │ └── CustomWebListener.java │ │ ├── initializer │ │ └── MyServletContextInitializer.java │ │ ├── servlet │ │ ├── SimpleServlet.java │ │ └── CustomServletRegistrationBean.java │ │ ├── bean │ │ └── ConfigurationBean.java │ │ ├── custom │ │ └── MyEmbeddedServletContainerCustomizer.java │ │ ├── controller │ │ ├── SimpleController.java │ │ └── TestController.java │ │ └── exception │ │ └── ExceptionControllerAdvice.java └── pom.xml ├── springboot-environment-loader ├── src │ └── main │ │ ├── resources │ │ ├── application-prod.yml │ │ ├── bak1 │ │ │ ├── application-dev.yml │ │ │ └── application.yml │ │ ├── bak2 │ │ │ ├── application-prod.yml │ │ │ └── application.yml │ │ └── application.yml │ │ └── java │ │ └── spring │ │ └── study │ │ └── property │ │ └── loader │ │ ├── SpringEnvironmentPropertySourceApplication.java │ │ └── processor │ │ └── CustomBeanFactoryPostProcessor.java └── pom.xml ├── springboot-only-test ├── src │ └── main │ │ ├── resources │ │ └── application.yml │ │ └── java │ │ └── spring │ │ └── study │ │ └── mytest │ │ ├── MyTestApplication.java │ │ └── controller │ │ └── TestController.java └── pom.xml ├── springboot-refresh-context ├── src │ └── main │ │ ├── resources │ │ ├── simple.properties │ │ └── import.xml │ │ └── java │ │ └── spring │ │ └── study │ │ └── refresh │ │ └── context │ │ ├── bean │ │ ├── SimpleServiceInXml.java │ │ ├── SimpleBeanInListener.java │ │ ├── SimpleBeanInBeanFactoryPostProcessor.java │ │ ├── SimpleBeanInBeanDefinitionRegistryPostProcessor.java │ │ ├── SimpleBeanWithDefinitionInBeanFactoryPostProcessor.java │ │ ├── SimpleBeanWithDefinitionInBeanDefinitionRegistryPostProcessor.java │ │ ├── NotHandleService.java │ │ ├── SimpleServiceInImportService.java │ │ ├── ImportService.java │ │ └── SimpleService.java │ │ ├── beanprocessor │ │ ├── MyBeanPostProcessor.java │ │ ├── MyBeanDefinitionRegistryPostProcessor.java │ │ └── MyBeanFactoryPostProcessor.java │ │ ├── RefreshContextApplication.java │ │ ├── lifecycle │ │ └── MyLifecycleBean.java │ │ └── listener │ │ └── MyApplicationListener.java └── pom.xml ├── log-module ├── src │ └── main │ │ ├── resources │ │ └── META-INF │ │ │ └── spring.factories │ │ └── java │ │ └── me │ │ └── format │ │ └── springboot │ │ └── log │ │ ├── annotation │ │ └── Log.java │ │ ├── autoconfigure │ │ ├── LogProperties.java │ │ └── LogAutoConfiguration.java │ │ └── aop │ │ └── LogMethodInterceptor.java └── pom.xml ├── springboot-logging-system ├── src │ └── main │ │ ├── resources │ │ ├── application.yml │ │ └── logback-spring.xml │ │ └── java │ │ └── spring │ │ └── study │ │ └── logging │ │ └── LoggingApplication.java └── pom.xml ├── spring-custom-component-provider ├── src │ ├── main │ │ ├── java │ │ │ ├── spring │ │ │ │ └── study │ │ │ │ │ └── componentprovider │ │ │ │ │ ├── interfaze │ │ │ │ │ ├── IConsumer.java │ │ │ │ │ └── IProducer.java │ │ │ │ │ ├── bean │ │ │ │ │ ├── ConsumerWithNothing.java │ │ │ │ │ ├── ConsumerWithInterface.java │ │ │ │ │ ├── ProducerWithInterface.java │ │ │ │ │ ├── ConsumerWithConsumerAnnotation.java │ │ │ │ │ └── ConsumerWithComponentAnnotation.java │ │ │ │ │ ├── annotation │ │ │ │ │ ├── Consumer.java │ │ │ │ │ └── EnableConsumer.java │ │ │ │ │ ├── CustomComponentProviderApplication.java │ │ │ │ │ └── spring │ │ │ │ │ └── ConsumerRegistrar.java │ │ │ └── other │ │ │ │ └── pkg │ │ │ │ └── OtherBean.java │ │ └── resources │ │ │ └── beans.xml │ └── test │ │ └── java │ │ └── spring │ │ └── study │ │ └── componentprovider │ │ └── test │ │ └── SpringEmbeddedProviderTest.java └── pom.xml ├── springboot-startup ├── src │ └── main │ │ ├── resources │ │ └── META-INF │ │ │ └── spring.factories │ │ └── java │ │ └── spring │ │ └── study │ │ └── startup │ │ ├── bean │ │ └── SimpleBean.java │ │ ├── runner │ │ ├── SimpleCommandLineRunner.java │ │ └── SimpleApplicationRunner.java │ │ ├── MySpringApplication.java │ │ ├── listeners │ │ └── SimpleApplicationListener.java │ │ └── initializers │ │ └── SimpleApplicationContextInitializer.java └── pom.xml ├── .gitignore ├── springboot-executable-jar ├── src │ ├── main │ │ └── java │ │ │ └── spring │ │ │ └── study │ │ │ └── executablejar │ │ │ └── ExecutableJarApplication.java │ └── test │ │ └── java │ │ └── spring │ │ └── study │ │ └── executablejar │ │ └── classloader │ │ └── test │ │ └── LaunchedURLClassLoaderTest.java └── pom.xml ├── LICENSE └── README.md /springboot-conditional/src/main/resources/mybatis.xml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /springboot-factories-loader/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /spring-bean-post-processor/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | test.prop: 1 -------------------------------------------------------------------------------- /springboot-conditional/src/main/resources/application-dev.yml: -------------------------------------------------------------------------------- 1 | server.host: localhost -------------------------------------------------------------------------------- /springboot-conditional/src/main/resources/application-prod.yml: -------------------------------------------------------------------------------- 1 | server.host: test -------------------------------------------------------------------------------- /springboot-embedded-servlet-conatiner/src/main/resources/static/404.html: -------------------------------------------------------------------------------- 1 | 404.html -------------------------------------------------------------------------------- /springboot-environment-loader/src/main/resources/application-prod.yml: -------------------------------------------------------------------------------- 1 | my.age: 111 -------------------------------------------------------------------------------- /springboot-embedded-servlet-conatiner/src/main/resources/templates/error.ftl.1: -------------------------------------------------------------------------------- 1 | error.ftl -------------------------------------------------------------------------------- /springboot-environment-loader/src/main/resources/bak1/application-dev.yml: -------------------------------------------------------------------------------- 1 | test.name: 1 -------------------------------------------------------------------------------- /springboot-only-test/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | mylog.exclude: "core,internal" -------------------------------------------------------------------------------- /springboot-conditional/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | `spring: 2 | profiles: 3 | active: prod -------------------------------------------------------------------------------- /springboot-environment-loader/src/main/resources/bak2/application-prod.yml: -------------------------------------------------------------------------------- 1 | my.age: 111 2 | my.name: 333 -------------------------------------------------------------------------------- /springboot-refresh-context/src/main/resources/simple.properties: -------------------------------------------------------------------------------- 1 | name=format 2 | hobbies=gundam,dota2 -------------------------------------------------------------------------------- /springboot-environment-loader/src/main/resources/bak1/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | profiles: 3 | active: dev -------------------------------------------------------------------------------- /springboot-environment-loader/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | profiles: 3 | active: prod 4 | 5 | my.name: 222 -------------------------------------------------------------------------------- /log-module/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | me.format.springboot.log.autoconfigure.LogAutoConfiguration -------------------------------------------------------------------------------- /springboot-environment-loader/src/main/resources/bak2/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | profiles: prod 3 | my.name: 1 4 | 5 | --- 6 | 7 | spring: 8 | profiles: dev 9 | my.name: 2 -------------------------------------------------------------------------------- /springboot-logging-system/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | #debug: false 2 | #trace: true 3 | logging: 4 | file: /tmp/temp.log 5 | # config: classpath:logback-spring.xml 6 | # path: /tmp 7 | 8 | -------------------------------------------------------------------------------- /springboot-conditional/src/main/java/spring/study/conditional/bean/ConditionNoneBean.java: -------------------------------------------------------------------------------- 1 | package spring.study.conditional.bean; 2 | 3 | /** 4 | * Created by Format on 2017/5/12. 5 | */ 6 | public class ConditionNoneBean { 7 | } 8 | -------------------------------------------------------------------------------- /springboot-refresh-context/src/main/java/spring/study/refresh/context/bean/SimpleServiceInXml.java: -------------------------------------------------------------------------------- 1 | package spring.study.refresh.context.bean; 2 | 3 | /** 4 | * Created by Format on 2017/5/4. 5 | */ 6 | public class SimpleServiceInXml { 7 | } 8 | -------------------------------------------------------------------------------- /springboot-refresh-context/src/main/java/spring/study/refresh/context/bean/SimpleBeanInListener.java: -------------------------------------------------------------------------------- 1 | package spring.study.refresh.context.bean; 2 | 3 | /** 4 | * Created by Format on 2017/5/10. 5 | */ 6 | public class SimpleBeanInListener { 7 | } 8 | -------------------------------------------------------------------------------- /spring-custom-component-provider/src/main/java/spring/study/componentprovider/interfaze/IConsumer.java: -------------------------------------------------------------------------------- 1 | package spring.study.componentprovider.interfaze; 2 | 3 | /** 4 | * Created by Format on 2017/6/11. 5 | */ 6 | public interface IConsumer { 7 | } 8 | -------------------------------------------------------------------------------- /spring-custom-component-provider/src/main/java/spring/study/componentprovider/interfaze/IProducer.java: -------------------------------------------------------------------------------- 1 | package spring.study.componentprovider.interfaze; 2 | 3 | /** 4 | * Created by Format on 2017/6/11. 5 | */ 6 | public interface IProducer { 7 | } 8 | -------------------------------------------------------------------------------- /spring-custom-component-provider/src/main/java/other/pkg/OtherBean.java: -------------------------------------------------------------------------------- 1 | package other.pkg; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | /** 6 | * Created by Format on 2017/6/15. 7 | */ 8 | @Component 9 | public class OtherBean { 10 | } 11 | -------------------------------------------------------------------------------- /springboot-embedded-servlet-conatiner/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server.context-parameters.paramA: a 2 | server.context-parameters.paramB: b 3 | server: 4 | session: 5 | timeout: 1000 6 | error: 7 | path: /errerr 8 | # whitelabel: 9 | # enabled: false -------------------------------------------------------------------------------- /spring-custom-component-provider/src/main/java/spring/study/componentprovider/bean/ConsumerWithNothing.java: -------------------------------------------------------------------------------- 1 | package spring.study.componentprovider.bean; 2 | 3 | 4 | 5 | /** 6 | * Created by Format on 2017/6/11. 7 | */ 8 | public class ConsumerWithNothing { 9 | } 10 | -------------------------------------------------------------------------------- /spring-bean-post-processor/src/main/java/spring/study/beanpostproessor/bean/ISimpleService.java: -------------------------------------------------------------------------------- 1 | package spring.study.beanpostproessor.bean; 2 | 3 | /** 4 | * Created by Format on 2017/6/18. 5 | */ 6 | public interface ISimpleService { 7 | void doSomething(Object arg); 8 | } 9 | -------------------------------------------------------------------------------- /springboot-refresh-context/src/main/java/spring/study/refresh/context/bean/SimpleBeanInBeanFactoryPostProcessor.java: -------------------------------------------------------------------------------- 1 | package spring.study.refresh.context.bean; 2 | 3 | /** 4 | * Created by Format on 2017/5/9. 5 | */ 6 | public class SimpleBeanInBeanFactoryPostProcessor { 7 | } 8 | -------------------------------------------------------------------------------- /springboot-refresh-context/src/main/java/spring/study/refresh/context/bean/SimpleBeanInBeanDefinitionRegistryPostProcessor.java: -------------------------------------------------------------------------------- 1 | package spring.study.refresh.context.bean; 2 | 3 | /** 4 | * Created by Format on 2017/5/9. 5 | */ 6 | public class SimpleBeanInBeanDefinitionRegistryPostProcessor { 7 | } 8 | -------------------------------------------------------------------------------- /springboot-refresh-context/src/main/java/spring/study/refresh/context/bean/SimpleBeanWithDefinitionInBeanFactoryPostProcessor.java: -------------------------------------------------------------------------------- 1 | package spring.study.refresh.context.bean; 2 | 3 | /** 4 | * Created by Format on 2017/5/9. 5 | */ 6 | public class SimpleBeanWithDefinitionInBeanFactoryPostProcessor { 7 | } 8 | -------------------------------------------------------------------------------- /springboot-startup/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.context.ApplicationContextInitializer=\ 2 | spring.study.startup.initializers.SimpleApplicationContextInitializer 3 | 4 | 5 | org.springframework.context.ApplicationListener=\ 6 | spring.study.startup.listeners.SimpleApplicationListener -------------------------------------------------------------------------------- /springboot-refresh-context/src/main/java/spring/study/refresh/context/bean/SimpleBeanWithDefinitionInBeanDefinitionRegistryPostProcessor.java: -------------------------------------------------------------------------------- 1 | package spring.study.refresh.context.bean; 2 | 3 | /** 4 | * Created by Format on 2017/5/9. 5 | */ 6 | public class SimpleBeanWithDefinitionInBeanDefinitionRegistryPostProcessor { 7 | } 8 | -------------------------------------------------------------------------------- /springboot-refresh-context/src/main/java/spring/study/refresh/context/bean/NotHandleService.java: -------------------------------------------------------------------------------- 1 | package spring.study.refresh.context.bean; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | /** 6 | * Created by Format on 2017/5/4. 7 | */ 8 | public class NotHandleService { 9 | 10 | private String name = "notHandle"; 11 | 12 | } 13 | -------------------------------------------------------------------------------- /spring-custom-component-provider/src/main/java/spring/study/componentprovider/bean/ConsumerWithInterface.java: -------------------------------------------------------------------------------- 1 | package spring.study.componentprovider.bean; 2 | 3 | 4 | import spring.study.componentprovider.interfaze.IConsumer; 5 | 6 | /** 7 | * Created by Format on 2017/6/11. 8 | */ 9 | public class ConsumerWithInterface implements IConsumer { 10 | } 11 | -------------------------------------------------------------------------------- /spring-custom-component-provider/src/main/java/spring/study/componentprovider/bean/ProducerWithInterface.java: -------------------------------------------------------------------------------- 1 | package spring.study.componentprovider.bean; 2 | 3 | 4 | import spring.study.componentprovider.interfaze.IProducer; 5 | 6 | /** 7 | * Created by Format on 2017/6/11. 8 | */ 9 | public class ProducerWithInterface implements IProducer { 10 | } 11 | -------------------------------------------------------------------------------- /spring-custom-component-provider/src/main/java/spring/study/componentprovider/bean/ConsumerWithConsumerAnnotation.java: -------------------------------------------------------------------------------- 1 | package spring.study.componentprovider.bean; 2 | 3 | import spring.study.componentprovider.annotation.Consumer; 4 | 5 | /** 6 | * Created by Format on 2017/6/10. 7 | */ 8 | @Consumer 9 | public class ConsumerWithConsumerAnnotation { 10 | } 11 | -------------------------------------------------------------------------------- /springboot-refresh-context/src/main/java/spring/study/refresh/context/bean/SimpleServiceInImportService.java: -------------------------------------------------------------------------------- 1 | package spring.study.refresh.context.bean; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | /** 6 | * Created by Format on 2017/5/4. 7 | */ 8 | public class SimpleServiceInImportService { 9 | 10 | private String name = "simpleServiceInImportService"; 11 | 12 | } 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Operating System Files 2 | 3 | *.DS_Store 4 | Thumbs.db 5 | *.sw? 6 | .#* 7 | *# 8 | *~ 9 | *.sublime-* 10 | 11 | # Build Artifacts 12 | 13 | .gradle/ 14 | build/ 15 | target/ 16 | bin/ 17 | dependency-reduced-pom.xml 18 | 19 | # Eclipse Project Files 20 | 21 | .classpath 22 | .project 23 | .settings/ 24 | 25 | # IntelliJ IDEA Files 26 | 27 | *.iml 28 | *.ipr 29 | *.iws 30 | *.idea 31 | 32 | -------------------------------------------------------------------------------- /spring-custom-component-provider/src/main/java/spring/study/componentprovider/bean/ConsumerWithComponentAnnotation.java: -------------------------------------------------------------------------------- 1 | package spring.study.componentprovider.bean; 2 | 3 | import org.springframework.stereotype.Component; 4 | import spring.study.componentprovider.annotation.Consumer; 5 | 6 | /** 7 | * Created by Format on 2017/6/10. 8 | */ 9 | @Component 10 | public class ConsumerWithComponentAnnotation { 11 | } 12 | -------------------------------------------------------------------------------- /springboot-conditional/src/main/java/spring/study/conditional/condition/ConditionBeanInXml.java: -------------------------------------------------------------------------------- 1 | package spring.study.conditional.condition; 2 | 3 | import org.springframework.boot.autoconfigure.condition.ConditionalOnJava; 4 | import org.springframework.stereotype.Component; 5 | 6 | /** 7 | * Created by Format on 2017/5/11. 8 | */ 9 | @ConditionalOnJava(ConditionalOnJava.JavaVersion.NINE) 10 | public class ConditionBeanInXml { 11 | } 12 | -------------------------------------------------------------------------------- /springboot-conditional/src/main/java/spring/study/conditional/bean/ConditionResourceBean.java: -------------------------------------------------------------------------------- 1 | package spring.study.conditional.bean; 2 | 3 | import org.springframework.boot.autoconfigure.condition.ConditionalOnResource; 4 | import org.springframework.stereotype.Component; 5 | 6 | /** 7 | * Created by Format on 2017/5/16. 8 | */ 9 | @ConditionalOnResource(resources = "mybatis.xml") 10 | @Component 11 | public class ConditionResourceBean { 12 | } 13 | -------------------------------------------------------------------------------- /spring-bean-post-processor/src/main/java/spring/study/beanpostproessor/bean/SimpleServiceForMerged.java: -------------------------------------------------------------------------------- 1 | package spring.study.beanpostproessor.bean; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | /** 6 | * Created by Format on 2017/6/20. 7 | */ 8 | @Component 9 | public class SimpleServiceForMerged { 10 | public SimpleServiceForMerged() { 11 | System.err.println("SimpleServiceForMerged constructor default"); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /springboot-startup/src/main/java/spring/study/startup/bean/SimpleBean.java: -------------------------------------------------------------------------------- 1 | package spring.study.startup.bean; 2 | 3 | import lombok.*; 4 | import org.springframework.stereotype.Component; 5 | 6 | /** 7 | * Created by Format on 2017/5/1. 8 | */ 9 | @Getter 10 | @Setter 11 | @ToString 12 | @Component 13 | @AllArgsConstructor 14 | @NoArgsConstructor 15 | public class SimpleBean { 16 | 17 | private String id; 18 | private String name; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /log-module/src/main/java/me/format/springboot/log/annotation/Log.java: -------------------------------------------------------------------------------- 1 | package me.format.springboot.log.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Created by format on 16/11/15. 10 | */ 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target(ElementType.METHOD) 13 | public @interface Log { 14 | } 15 | -------------------------------------------------------------------------------- /spring-bean-post-processor/src/main/java/spring/study/beanpostproessor/bean/ReferenceA.java: -------------------------------------------------------------------------------- 1 | package spring.study.beanpostproessor.bean; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Component; 5 | 6 | /** 7 | * Created by Format on 2017/6/20. 8 | */ 9 | @Component 10 | public class ReferenceA { 11 | @Autowired 12 | private ReferenceB referenceB; 13 | public ReferenceA() { } 14 | } 15 | -------------------------------------------------------------------------------- /spring-bean-post-processor/src/main/java/spring/study/beanpostproessor/bean/SimpleServiceForDestroy.java: -------------------------------------------------------------------------------- 1 | package spring.study.beanpostproessor.bean; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | /** 6 | * Created by Format on 2017/6/20. 7 | */ 8 | @Component 9 | public class SimpleServiceForDestroy { 10 | public SimpleServiceForDestroy() { 11 | System.err.println("SimpleServiceForDestroy constructor default"); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /springboot-conditional/src/main/java/spring/study/conditional/bean/ConditionExpressionBean.java: -------------------------------------------------------------------------------- 1 | package spring.study.conditional.bean; 2 | 3 | import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; 4 | import org.springframework.stereotype.Component; 5 | 6 | /** 7 | * Created by Format on 2017/5/12. 8 | */ 9 | @ConditionalOnExpression("'${server.host}' == 'localhost'") 10 | @Component 11 | public class ConditionExpressionBean { 12 | } 13 | -------------------------------------------------------------------------------- /springboot-refresh-context/src/main/java/spring/study/refresh/context/bean/ImportService.java: -------------------------------------------------------------------------------- 1 | package spring.study.refresh.context.bean; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | 5 | /** 6 | * Created by Format on 2017/5/4. 7 | */ 8 | public class ImportService { 9 | 10 | @Bean 11 | public SimpleServiceInImportService simpleServiceInImportService() { 12 | return new SimpleServiceInImportService(); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /springboot-conditional/src/main/java/spring/study/conditional/condition/ConditionBeanWithComponent.java: -------------------------------------------------------------------------------- 1 | package spring.study.conditional.condition; 2 | 3 | import org.springframework.boot.autoconfigure.condition.ConditionalOnJava; 4 | import org.springframework.stereotype.Component; 5 | 6 | /** 7 | * Created by Format on 2017/5/11. 8 | */ 9 | @ConditionalOnJava(ConditionalOnJava.JavaVersion.NINE) 10 | @Component 11 | public class ConditionBeanWithComponent { 12 | } 13 | -------------------------------------------------------------------------------- /springboot-only-test/src/main/java/spring/study/mytest/MyTestApplication.java: -------------------------------------------------------------------------------- 1 | package spring.study.mytest; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * Created by Format on 2017/8/26. 8 | */ 9 | @SpringBootApplication 10 | public class MyTestApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(MyTestApplication.class, args); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springboot-executable-jar/src/main/java/spring/study/executablejar/ExecutableJarApplication.java: -------------------------------------------------------------------------------- 1 | package spring.study.executablejar; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * Created by Format on 2017/5/27. 8 | */ 9 | @SpringBootApplication 10 | public class ExecutableJarApplication { 11 | public static void main(String[] args) { 12 | SpringApplication.run(ExecutableJarApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /springboot-conditional/src/main/java/spring/study/conditional/bean/ConditionClassBean.java: -------------------------------------------------------------------------------- 1 | package spring.study.conditional.bean; 2 | 3 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; 4 | import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration; 5 | import org.springframework.stereotype.Component; 6 | 7 | /** 8 | * Created by Format on 2017/5/12. 9 | */ 10 | @ConditionalOnBean(value = FreeMarkerAutoConfiguration.class) 11 | @Component 12 | public class ConditionClassBean { 13 | } 14 | -------------------------------------------------------------------------------- /springboot-conditional/src/main/resources/import.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | -------------------------------------------------------------------------------- /springboot-startup/src/main/java/spring/study/startup/runner/SimpleCommandLineRunner.java: -------------------------------------------------------------------------------- 1 | package spring.study.startup.runner; 2 | 3 | import org.springframework.boot.CommandLineRunner; 4 | import org.springframework.stereotype.Component; 5 | 6 | /** 7 | * Created by Format on 2017/5/2. 8 | */ 9 | @Component 10 | public class SimpleCommandLineRunner implements CommandLineRunner { 11 | @Override 12 | public void run(String... args) throws Exception { 13 | System.out.println("===== SimpleCommandLineRunner"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot-refresh-context/src/main/resources/import.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | -------------------------------------------------------------------------------- /spring-custom-component-provider/src/main/java/spring/study/componentprovider/annotation/Consumer.java: -------------------------------------------------------------------------------- 1 | package spring.study.componentprovider.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Created by Format on 2017/6/10. 10 | */ 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target(ElementType.TYPE) 13 | public @interface Consumer { 14 | 15 | String value() default "none"; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /springboot-factories-loader/src/main/java/spring/study/factories/loader/SpringFactoriesApplication.java: -------------------------------------------------------------------------------- 1 | package spring.study.factories.loader; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * Created by Format on 2017/6/3. 8 | */ 9 | @SpringBootApplication 10 | public class SpringFactoriesApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(SpringFactoriesApplication.class, args); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springboot-only-test/src/main/java/spring/study/mytest/controller/TestController.java: -------------------------------------------------------------------------------- 1 | package spring.study.mytest.controller; 2 | 3 | import me.format.springboot.log.annotation.Log; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | /** 8 | * Created by Format on 2017/8/26. 9 | */ 10 | @RestController 11 | public class TestController { 12 | 13 | @Log 14 | @RequestMapping("/test") 15 | public String test() { 16 | return "only test"; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /spring-bean-post-processor/src/main/java/spring/study/beanpostproessor/bean/EmbeddedService.java: -------------------------------------------------------------------------------- 1 | package spring.study.beanpostproessor.bean; 2 | 3 | import lombok.Getter; 4 | import lombok.Setter; 5 | import lombok.ToString; 6 | import org.springframework.stereotype.Component; 7 | 8 | /** 9 | * Created by Format on 2017/6/19. 10 | */ 11 | //@Component 12 | @Setter 13 | @Getter 14 | @ToString 15 | public class EmbeddedService { 16 | public EmbeddedService() { 17 | System.err.println("constructor EmbeddedService"); 18 | } 19 | private String id; 20 | } 21 | -------------------------------------------------------------------------------- /spring-bean-post-processor/src/main/java/spring/study/beanpostproessor/embedded/BeanForAop.java: -------------------------------------------------------------------------------- 1 | package spring.study.beanpostproessor.embedded; 2 | 3 | import org.springframework.context.annotation.Scope; 4 | import org.springframework.stereotype.Component; 5 | 6 | import javax.validation.constraints.Min; 7 | import javax.validation.constraints.NotNull; 8 | 9 | /** 10 | * Created by Format on 2017/6/22. 11 | */ 12 | @Component 13 | public class BeanForAop { 14 | 15 | public void test() { 16 | System.err.println("bean for aop"); 17 | } 18 | 19 | } 20 | 21 | -------------------------------------------------------------------------------- /springboot-logging-system/src/main/resources/logback-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %d{YYYY-MM-dd} [%thread] %-5level %logger[%line] -- %msg%n 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /spring-bean-post-processor/src/main/java/spring/study/beanpostproessor/bean/ReferenceB.java: -------------------------------------------------------------------------------- 1 | package spring.study.beanpostproessor.bean; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Lazy; 5 | import org.springframework.stereotype.Component; 6 | 7 | /** 8 | * Created by Format on 2017/6/20. 9 | */ 10 | @Component 11 | public class ReferenceB { 12 | private ReferenceA referenceA; 13 | @Autowired 14 | public ReferenceB(ReferenceA referenceA) { 15 | this.referenceA = referenceA; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /spring-bean-post-processor/src/main/java/spring/study/beanpostproessor/embedded/BeanForSchedule.java: -------------------------------------------------------------------------------- 1 | package spring.study.beanpostproessor.embedded; 2 | 3 | import org.springframework.scheduling.annotation.Scheduled; 4 | import org.springframework.stereotype.Component; 5 | 6 | import java.util.Date; 7 | 8 | /** 9 | * Created by Format on 2017/6/22. 10 | */ 11 | @Component 12 | public class BeanForSchedule { 13 | 14 | @Scheduled(cron = "0/5 * * * * *") 15 | public void test() { 16 | System.err.println(new Date() + " schedule by5 * * * * *"); 17 | } 18 | 19 | } 20 | 21 | -------------------------------------------------------------------------------- /springboot-conditional/src/main/java/spring/study/conditional/condition/ConditionBeanInImport.java: -------------------------------------------------------------------------------- 1 | package spring.study.conditional.condition; 2 | 3 | import org.springframework.boot.autoconfigure.condition.ConditionalOnJava; 4 | import org.springframework.stereotype.Component; 5 | 6 | /** 7 | * Created by Format on 2017/5/11. 8 | */ 9 | @ConditionalOnJava(ConditionalOnJava.JavaVersion.NINE) 10 | public class ConditionBeanInImport { 11 | 12 | 13 | public SimpleBean simpleBean() { 14 | return new SimpleBean(); 15 | } 16 | 17 | class SimpleBean { 18 | 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /springboot-startup/src/main/java/spring/study/startup/runner/SimpleApplicationRunner.java: -------------------------------------------------------------------------------- 1 | package spring.study.startup.runner; 2 | 3 | import org.springframework.boot.ApplicationArguments; 4 | import org.springframework.boot.ApplicationRunner; 5 | import org.springframework.stereotype.Component; 6 | 7 | /** 8 | * Created by Format on 2017/5/2. 9 | */ 10 | @Component 11 | public class SimpleApplicationRunner implements ApplicationRunner { 12 | @Override 13 | public void run(ApplicationArguments args) throws Exception { 14 | System.out.println("===== SimpleApplicationRunner");; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /springboot-conditional/src/main/java/spring/study/conditional/bean/ConditionBeanBean.java: -------------------------------------------------------------------------------- 1 | package spring.study.conditional.bean; 2 | 3 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; 4 | import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; 5 | import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration; 6 | import org.springframework.stereotype.Component; 7 | 8 | /** 9 | * Created by Format on 2017/5/12. 10 | */ 11 | @ConditionalOnBean(value = FreeMarkerAutoConfiguration.class) 12 | @Component 13 | public class ConditionBeanBean { 14 | } 15 | -------------------------------------------------------------------------------- /springboot-environment-loader/src/main/java/spring/study/property/loader/SpringEnvironmentPropertySourceApplication.java: -------------------------------------------------------------------------------- 1 | package spring.study.property.loader; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * Created by Format on 2017/6/3. 8 | */ 9 | @SpringBootApplication 10 | public class SpringEnvironmentPropertySourceApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication sa = new SpringApplication(); 14 | sa.run(SpringEnvironmentPropertySourceApplication.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /spring-bean-post-processor/src/main/java/spring/study/beanpostproessor/embedded/BeanForAsync.java: -------------------------------------------------------------------------------- 1 | package spring.study.beanpostproessor.embedded; 2 | 3 | import org.springframework.scheduling.annotation.Async; 4 | import org.springframework.stereotype.Component; 5 | 6 | 7 | /** 8 | * Created by Format on 2017/6/23. 9 | */ 10 | @Component 11 | public class BeanForAsync { 12 | 13 | @Async 14 | public void async() { 15 | try { 16 | Thread.sleep(5000l); 17 | System.out.println("async over"); 18 | } catch (InterruptedException e) { 19 | e.printStackTrace(); 20 | } 21 | } 22 | 23 | 24 | } 25 | -------------------------------------------------------------------------------- /spring-custom-component-provider/src/main/resources/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /spring-bean-post-processor/src/main/java/spring/study/beanpostproessor/embedded/BeanForBeanValidation.java: -------------------------------------------------------------------------------- 1 | package spring.study.beanpostproessor.embedded; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import javax.validation.constraints.Min; 6 | import javax.validation.constraints.NotNull; 7 | 8 | /** 9 | * Created by Format on 2017/6/22. 10 | */ 11 | //@Component 12 | public class BeanForBeanValidation { 13 | 14 | public BeanForBeanValidation() { 15 | System.err.println("constructor BeanForBeanValidation"); 16 | } 17 | 18 | @NotNull 19 | private String id; 20 | 21 | @Min(value = 10) 22 | private int age; 23 | 24 | } 25 | 26 | -------------------------------------------------------------------------------- /spring-custom-component-provider/src/main/java/spring/study/componentprovider/annotation/EnableConsumer.java: -------------------------------------------------------------------------------- 1 | package spring.study.componentprovider.annotation; 2 | 3 | import org.springframework.context.annotation.Import; 4 | import spring.study.componentprovider.spring.ConsumerRegistrar; 5 | 6 | import java.lang.annotation.ElementType; 7 | import java.lang.annotation.Retention; 8 | import java.lang.annotation.RetentionPolicy; 9 | import java.lang.annotation.Target; 10 | 11 | /** 12 | * Created by Format on 2017/6/10. 13 | */ 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Target(ElementType.TYPE) 16 | @Import(ConsumerRegistrar.class) 17 | public @interface EnableConsumer { 18 | 19 | } 20 | -------------------------------------------------------------------------------- /spring-bean-post-processor/src/main/java/spring/study/beanpostproessor/embedded/BeanForMethodValidation.java: -------------------------------------------------------------------------------- 1 | package spring.study.beanpostproessor.embedded; 2 | 3 | import org.hibernate.validator.constraints.NotEmpty; 4 | import org.springframework.stereotype.Component; 5 | import org.springframework.validation.annotation.Validated; 6 | 7 | import javax.validation.constraints.Min; 8 | 9 | /** 10 | * Created by Format on 2017/6/23. 11 | */ 12 | @Component 13 | @Validated 14 | public class BeanForMethodValidation { 15 | 16 | public void validate(@NotEmpty String name, @Min(10) int age) { 17 | System.err.println("validate, name: " + name + ", age: " + age); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /springboot-embedded-servlet-conatiner/src/main/java/spring/study/embedded/servlet/EmbeddedServletApplication.java: -------------------------------------------------------------------------------- 1 | package spring.study.embedded.servlet; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.web.servlet.ServletComponentScan; 6 | 7 | /** 8 | * Created by Format on 2017/5/14. 9 | */ 10 | @SpringBootApplication 11 | @ServletComponentScan 12 | public class EmbeddedServletApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication sa = new SpringApplication(EmbeddedServletApplication.class); 16 | sa.run(args); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /springboot-embedded-servlet-conatiner/src/main/java/spring/study/embedded/servlet/listener/CustomWebListener.java: -------------------------------------------------------------------------------- 1 | package spring.study.embedded.servlet.listener; 2 | 3 | import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent; 4 | import org.springframework.context.ApplicationListener; 5 | 6 | /** 7 | * Created by Format on 2017/5/15. 8 | */ 9 | public class CustomWebListener implements ApplicationListener { 10 | @Override 11 | public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) { 12 | // 可以做一些参数的监测,如果不合格的话,直接stop 13 | // event.getEmbeddedServletContainer().stop(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /spring-bean-post-processor/src/main/java/spring/study/beanpostproessor/bean/SimpleServiceForSmart.java: -------------------------------------------------------------------------------- 1 | package spring.study.beanpostproessor.bean; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | /** 6 | * Created by Format on 2017/6/20. 7 | */ 8 | @Component 9 | public class SimpleServiceForSmart { 10 | private EmbeddedService embeddedService; 11 | public SimpleServiceForSmart() { 12 | System.err.println("SimpleServiceForSmart constructor default"); 13 | } 14 | public SimpleServiceForSmart(EmbeddedService embeddedService) { 15 | this.embeddedService = embeddedService; 16 | System.err.println("SimpleServiceForSmart constructor embeddedService: " + embeddedService); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /springboot-embedded-servlet-conatiner/src/main/java/spring/study/embedded/servlet/initializer/MyServletContextInitializer.java: -------------------------------------------------------------------------------- 1 | package spring.study.embedded.servlet.initializer; 2 | 3 | import org.springframework.boot.context.embedded.ServletContextInitializer; 4 | 5 | import javax.servlet.ServletContext; 6 | import javax.servlet.ServletException; 7 | 8 | /** 9 | * Created by Format on 2017/5/18. 10 | */ 11 | public class MyServletContextInitializer implements ServletContextInitializer { 12 | @Override 13 | public void onStartup(ServletContext servletContext) throws ServletException { 14 | // servletContext.addFilter(); 15 | // servletContext.addListener(); 16 | // servletContext.addServlet() 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /springboot-refresh-context/src/main/java/spring/study/refresh/context/bean/SimpleService.java: -------------------------------------------------------------------------------- 1 | package spring.study.refresh.context.bean; 2 | 3 | import org.springframework.beans.factory.BeanFactory; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.context.ApplicationContext; 6 | import org.springframework.stereotype.Component; 7 | 8 | /** 9 | * Created by Format on 2017/5/4. 10 | */ 11 | @Component 12 | public class SimpleService { 13 | 14 | private String name = "simple"; 15 | 16 | public SimpleService() { 17 | System.out.println("------ SimpleService constructor invoke"); 18 | } 19 | 20 | public void test() { 21 | System.out.println(name); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /spring-bean-post-processor/src/main/resources/rebel.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /springboot-embedded-servlet-conatiner/src/main/java/spring/study/embedded/servlet/servlet/SimpleServlet.java: -------------------------------------------------------------------------------- 1 | package spring.study.embedded.servlet.servlet; 2 | 3 | import javax.servlet.ServletException; 4 | import javax.servlet.annotation.WebServlet; 5 | import javax.servlet.http.HttpServlet; 6 | import javax.servlet.http.HttpServletRequest; 7 | import javax.servlet.http.HttpServletResponse; 8 | import java.io.IOException; 9 | 10 | /** 11 | * Created by Format on 2017/5/16. 12 | */ 13 | @WebServlet(urlPatterns = "/simple") 14 | public class SimpleServlet extends HttpServlet { 15 | 16 | @Override 17 | protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 18 | resp.getWriter().write("receive by SimpleServlet"); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /springboot-startup/src/main/java/spring/study/startup/MySpringApplication.java: -------------------------------------------------------------------------------- 1 | package spring.study.startup; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.ApplicationContext; 6 | import spring.study.startup.bean.SimpleBean; 7 | 8 | /** 9 | * Created by Format on 2017/5/1. 10 | */ 11 | @SpringBootApplication 12 | public class MySpringApplication { 13 | public static void main(String[] args) { 14 | ApplicationContext applicationContext = SpringApplication.run(MySpringApplication.class, args); 15 | SimpleBean sb = applicationContext.getBean("testBean", SimpleBean.class); 16 | System.out.println("id: " + sb.getId() + ", name: " + sb.getName()); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /spring-bean-post-processor/src/main/java/spring/study/beanpostproessor/embedded/BeanForAutowired.java: -------------------------------------------------------------------------------- 1 | package spring.study.beanpostproessor.embedded; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.beans.factory.annotation.Value; 5 | 6 | 7 | /** 8 | * Created by Format on 2017/6/21. 9 | */ 10 | //@Component 11 | public class BeanForAutowired { 12 | 13 | public BeanForAutowired() { 14 | System.err.println("constructor BeanForAutowired"); 15 | } 16 | 17 | @Autowired 18 | private AutowiredNestedBean nestedBean; 19 | 20 | @Value("${test.prop}") 21 | private String test; 22 | 23 | } 24 | 25 | 26 | //@Component 27 | class AutowiredNestedBean { 28 | public AutowiredNestedBean() { 29 | System.err.println("constructor AutowiredNestedBean"); 30 | } 31 | } -------------------------------------------------------------------------------- /springboot-conditional/src/main/java/spring/study/conditional/ConditionalApplication.java: -------------------------------------------------------------------------------- 1 | package spring.study.conditional; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.Import; 6 | import org.springframework.context.annotation.ImportResource; 7 | import spring.study.conditional.condition.ConditionBeanInImport; 8 | 9 | /** 10 | * Created by Format on 2017/5/11. 11 | */ 12 | @SpringBootApplication 13 | @ImportResource("classpath:import.xml") 14 | @Import(ConditionBeanInImport.class) 15 | public class ConditionalApplication { 16 | 17 | public static void main(String[] args) { 18 | SpringApplication sa = new SpringApplication(ConditionalApplication.class); 19 | sa.run(args); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /springboot-embedded-servlet-conatiner/src/main/java/spring/study/embedded/servlet/bean/ConfigurationBean.java: -------------------------------------------------------------------------------- 1 | package spring.study.embedded.servlet.bean; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.servlet.DispatcherServlet; 6 | 7 | /** 8 | * Created by Format on 2017/5/18. 9 | */ 10 | @Configuration 11 | public class ConfigurationBean { 12 | 13 | // @Bean(name = "dispatcherServlet") // 这样就不会构造DispatcherServlet,@Controller注解就无法生效了 14 | public Object test() { 15 | return new Object(); 16 | } 17 | 18 | 19 | @Bean(name = "dispatcherServlet") // 在ServletContextInitializerBeans中调用addAdaptableBeans包装成ServletRegistrationBean 20 | public DispatcherServlet myDispatcherServlet() { 21 | return new DispatcherServlet(); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /log-module/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | me.format.springboot 8 | log-starter 9 | 3.0-SNAPSHOT 10 | 11 | 12 | org.springframework.boot 13 | spring-boot-starter-parent 14 | 1.3.5.RELEASE 15 | 16 | 17 | 18 | 19 | org.springframework.boot 20 | spring-boot-starter 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /log-module/src/main/java/me/format/springboot/log/autoconfigure/LogProperties.java: -------------------------------------------------------------------------------- 1 | package me.format.springboot.log.autoconfigure; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | import org.springframework.util.StringUtils; 5 | 6 | import javax.annotation.PostConstruct; 7 | 8 | /** 9 | * Created by format on 16/11/16. 10 | */ 11 | @ConfigurationProperties(prefix = "mylog") 12 | public class LogProperties { 13 | 14 | private String exclude; 15 | 16 | private String[] excludeArr; 17 | 18 | @PostConstruct 19 | public void init() { 20 | this.excludeArr = StringUtils.split(exclude, ","); 21 | } 22 | 23 | public String getExclude() { 24 | return exclude; 25 | } 26 | 27 | public void setExclude(String exclude) { 28 | this.exclude = exclude; 29 | } 30 | 31 | public String[] getExcludeArr() { 32 | return excludeArr; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /springboot-startup/src/main/java/spring/study/startup/listeners/SimpleApplicationListener.java: -------------------------------------------------------------------------------- 1 | package spring.study.startup.listeners; 2 | 3 | import org.springframework.boot.context.event.ApplicationReadyEvent; 4 | import org.springframework.boot.context.event.ApplicationStartedEvent; 5 | import org.springframework.context.ApplicationEvent; 6 | import org.springframework.context.ApplicationListener; 7 | 8 | /** 9 | * Created by Format on 2017/5/1. 10 | */ 11 | public class SimpleApplicationListener implements ApplicationListener { 12 | @Override 13 | public void onApplicationEvent(ApplicationEvent event) { 14 | if(event instanceof ApplicationStartedEvent) { 15 | System.out.println("===== custom started event in initializer"); 16 | } else if(event instanceof ApplicationReadyEvent) { 17 | System.out.println("===== custom ready event in initializer"); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /springboot-embedded-servlet-conatiner/src/main/java/spring/study/embedded/servlet/custom/MyEmbeddedServletContainerCustomizer.java: -------------------------------------------------------------------------------- 1 | package spring.study.embedded.servlet.custom; 2 | 3 | import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer; 4 | import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; 5 | import org.springframework.boot.context.embedded.ErrorPage; 6 | import org.springframework.http.HttpStatus; 7 | import org.springframework.stereotype.Component; 8 | 9 | /** 10 | * Created by Format on 2017/5/18. 11 | */ 12 | @Component 13 | public class MyEmbeddedServletContainerCustomizer implements EmbeddedServletContainerCustomizer { 14 | @Override 15 | public void customize(ConfigurableEmbeddedServletContainer container) { 16 | // container.setContextPath("/format"); 17 | container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/404.html")); 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /springboot-embedded-servlet-conatiner/src/main/java/spring/study/embedded/servlet/controller/SimpleController.java: -------------------------------------------------------------------------------- 1 | package spring.study.embedded.servlet.controller; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.stereotype.Controller; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.ResponseBody; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | /** 10 | * Created by Format on 2017/5/15. 11 | */ 12 | @Controller 13 | public class SimpleController { 14 | 15 | @RequestMapping("/myView") 16 | public String custom() { 17 | return "1"; 18 | } 19 | 20 | @RequestMapping("/myError") 21 | public String simple() { 22 | throw new RuntimeException("my exception"); 23 | } 24 | 25 | @RequestMapping("/error") 26 | @ResponseBody 27 | public String error() { 28 | return "my error"; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /spring-bean-post-processor/src/main/java/spring/study/beanpostproessor/embedded/BeanForRequired.java: -------------------------------------------------------------------------------- 1 | package spring.study.beanpostproessor.embedded; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.beans.factory.annotation.Required; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.stereotype.Component; 7 | 8 | /** 9 | * Created by Format on 2017/6/22. 10 | */ 11 | //@Component 12 | public class BeanForRequired { 13 | 14 | public BeanForRequired() { 15 | System.err.println("constructor BeanForRequired"); 16 | } 17 | 18 | private RequiredNestedBean nestedBean; 19 | 20 | @Required 21 | public void setNestedBean(RequiredNestedBean nestedBean) { 22 | this.nestedBean = nestedBean; 23 | } 24 | } 25 | 26 | 27 | //@Component 28 | class RequiredNestedBean { 29 | public RequiredNestedBean() { 30 | System.err.println("constructor RequiredNestedBean"); 31 | } 32 | } -------------------------------------------------------------------------------- /springboot-embedded-servlet-conatiner/src/main/java/spring/study/embedded/servlet/exception/ExceptionControllerAdvice.java: -------------------------------------------------------------------------------- 1 | package spring.study.embedded.servlet.exception; 2 | 3 | import org.springframework.web.bind.annotation.ExceptionHandler; 4 | import org.springframework.web.bind.annotation.ResponseBody; 5 | 6 | import javax.servlet.http.HttpServletRequest; 7 | import javax.servlet.http.HttpServletResponse; 8 | import java.util.HashMap; 9 | import java.util.Map; 10 | 11 | /** 12 | * Created by Format on 2017/5/20. 13 | */ 14 | //@ControllerAdvice // 启动的话。错误页都会被这里截获,而不走whitelabel error page 15 | public class ExceptionControllerAdvice { 16 | 17 | @ExceptionHandler(Throwable.class) 18 | @ResponseBody 19 | public Map ajaxError(Throwable error, HttpServletRequest request, HttpServletResponse response) { 20 | Map map = new HashMap<>(); 21 | map.put("error", error.getMessage()); 22 | map.put("result", "error"); 23 | return map; 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /springboot-startup/src/main/java/spring/study/startup/initializers/SimpleApplicationContextInitializer.java: -------------------------------------------------------------------------------- 1 | package spring.study.startup.initializers; 2 | 3 | import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; 4 | import org.springframework.context.ApplicationContextInitializer; 5 | import org.springframework.context.ConfigurableApplicationContext; 6 | import spring.study.startup.bean.SimpleBean; 7 | 8 | /** 9 | * Created by Format on 2017/5/1. 10 | */ 11 | public class SimpleApplicationContextInitializer implements ApplicationContextInitializer { 12 | @Override 13 | public void initialize(ConfigurableApplicationContext applicationContext) { 14 | if(applicationContext instanceof AnnotationConfigEmbeddedWebApplicationContext) { 15 | ((AnnotationConfigEmbeddedWebApplicationContext)applicationContext).getBeanFactory().registerSingleton("testBean", new SimpleBean("id-001", "created by initializer")); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /springboot-conditional/src/main/java/spring/study/conditional/bean/MyConditionalBean.java: -------------------------------------------------------------------------------- 1 | package spring.study.conditional.bean; 2 | 3 | import org.springframework.context.annotation.Condition; 4 | import org.springframework.context.annotation.ConditionContext; 5 | import org.springframework.context.annotation.Conditional; 6 | import org.springframework.core.type.AnnotatedTypeMetadata; 7 | import org.springframework.stereotype.Component; 8 | 9 | import java.util.Arrays; 10 | 11 | /** 12 | * Created by Format on 2017/6/2. 13 | */ 14 | @Conditional(MyCondition.class) 15 | @Component 16 | public class MyConditionalBean { 17 | } 18 | 19 | 20 | class MyCondition implements Condition { 21 | 22 | @Override 23 | public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { 24 | System.out.println("===== " + Arrays.toString(context.getEnvironment().getActiveProfiles())); 25 | System.out.println("===== " + context.getEnvironment().getProperty("server.host")); 26 | return false; 27 | } 28 | } -------------------------------------------------------------------------------- /spring-bean-post-processor/src/main/java/spring/study/beanpostproessor/embedded/BeanForCommon.java: -------------------------------------------------------------------------------- 1 | package spring.study.beanpostproessor.embedded; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import javax.annotation.PostConstruct; 6 | import javax.annotation.PreDestroy; 7 | import javax.annotation.Resource; 8 | 9 | /** 10 | * Created by Format on 2017/6/21. 11 | */ 12 | //@Component 13 | public class BeanForCommon { 14 | 15 | public BeanForCommon() { 16 | System.err.println("constructor BeanForCommon"); 17 | } 18 | 19 | @Resource 20 | private CommonNestedBean nestedBean; 21 | 22 | @PostConstruct 23 | public void init() { 24 | System.err.println("BeanForCommon PostConstruct"); 25 | } 26 | 27 | @PreDestroy 28 | public void destroy() { 29 | System.err.println("BeanForCommon PreDestroy"); 30 | } 31 | 32 | } 33 | 34 | 35 | //@Component 36 | class CommonNestedBean { 37 | public CommonNestedBean() { 38 | System.err.println("constructor CommonNestedBean"); 39 | } 40 | } -------------------------------------------------------------------------------- /springboot-logging-system/src/main/java/spring/study/logging/LoggingApplication.java: -------------------------------------------------------------------------------- 1 | package spring.study.logging; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.boot.CommandLineRunner; 6 | import org.springframework.boot.SpringApplication; 7 | import org.springframework.boot.autoconfigure.SpringBootApplication; 8 | import org.springframework.context.annotation.Bean; 9 | 10 | /** 11 | * Created by Format on 2017/8/18. 12 | */ 13 | @SpringBootApplication 14 | public class LoggingApplication { 15 | 16 | Logger logger = LoggerFactory.getLogger(LoggingApplication.class); 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(LoggingApplication.class, args); 20 | } 21 | 22 | @Bean 23 | public CommandLineRunner runner() { 24 | return new CommandLineRunner() { 25 | 26 | @Override 27 | public void run(String... args) throws Exception { 28 | logger.info("runner execute"); 29 | } 30 | }; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /spring-bean-post-processor/src/main/java/spring/study/beanpostproessor/aop/MyAspect.java: -------------------------------------------------------------------------------- 1 | package spring.study.beanpostproessor.aop; 2 | 3 | import org.aspectj.lang.JoinPoint; 4 | import org.aspectj.lang.ProceedingJoinPoint; 5 | import org.aspectj.lang.annotation.Around; 6 | import org.aspectj.lang.annotation.Aspect; 7 | import org.aspectj.lang.annotation.Before; 8 | import org.springframework.stereotype.Component; 9 | 10 | /** 11 | * Created by Format on 2017/6/22. 12 | */ 13 | @Aspect 14 | @Component 15 | public class MyAspect { 16 | 17 | @Around("execution(public * spring.study.beanpostproessor.embedded.BeanForAop.*(..))") 18 | public Object declareJointPointExpression(ProceedingJoinPoint proceedingJoinPoint) { 19 | System.out.println("before aop"); 20 | Object result = null; 21 | try { 22 | result = proceedingJoinPoint.proceed(proceedingJoinPoint.getArgs()); 23 | } catch (Throwable throwable) { 24 | throwable.printStackTrace(); 25 | } 26 | System.out.println("after aop"); 27 | return result; 28 | } 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /spring-bean-post-processor/src/main/java/spring/study/beanpostproessor/bean/SimpleServiceImpl.java: -------------------------------------------------------------------------------- 1 | package spring.study.beanpostproessor.bean; 2 | 3 | import lombok.Getter; 4 | import lombok.Setter; 5 | import lombok.ToString; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.beans.factory.annotation.Lookup; 8 | import org.springframework.beans.factory.annotation.Required; 9 | import org.springframework.beans.factory.annotation.Value; 10 | import org.springframework.stereotype.Component; 11 | 12 | /** 13 | * Created by Format on 2017/6/18. 14 | */ 15 | @Getter 16 | @Setter 17 | @ToString 18 | @Component 19 | public class SimpleServiceImpl implements ISimpleService { 20 | // @Autowired 21 | private EmbeddedService embeddedService; 22 | // public SimpleServiceImpl() { } 23 | @Autowired 24 | public SimpleServiceImpl(EmbeddedService embeddedService) { 25 | this.embeddedService = embeddedService; 26 | } 27 | @Override 28 | public void doSomething(Object arg) { 29 | System.out.println("----- doSomething with: " + arg); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /springboot-refresh-context/src/main/java/spring/study/refresh/context/beanprocessor/MyBeanPostProcessor.java: -------------------------------------------------------------------------------- 1 | package spring.study.refresh.context.beanprocessor; 2 | 3 | import org.springframework.beans.BeansException; 4 | import org.springframework.beans.factory.config.BeanPostProcessor; 5 | import org.springframework.stereotype.Component; 6 | 7 | /** 8 | * Created by Format on 2017/5/8. 9 | */ 10 | @Component 11 | public class MyBeanPostProcessor implements BeanPostProcessor { 12 | 13 | public MyBeanPostProcessor() { 14 | System.out.println("------ MyBeanPostProcessor construct"); 15 | } 16 | 17 | @Override 18 | public Object postProcessBeforeInitialization(Object bean, String arg1) 19 | throws BeansException { 20 | System.out.println("------ MyBeanPostProcessor before initialization"); 21 | return bean; 22 | } 23 | 24 | @Override 25 | public Object postProcessAfterInitialization(Object bean, String arg1) 26 | throws BeansException { 27 | System.out.println("------ MyBeanPostProcessor after initialization"); 28 | return bean; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 format 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /spring-bean-post-processor/src/main/java/spring/study/beanpostproessor/registrar/SimpleRegistrar.java: -------------------------------------------------------------------------------- 1 | package spring.study.beanpostproessor.registrar; 2 | 3 | import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition; 4 | import org.springframework.beans.factory.support.BeanDefinitionRegistry; 5 | import org.springframework.beans.factory.support.RootBeanDefinition; 6 | import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; 7 | import org.springframework.core.type.AnnotationMetadata; 8 | import spring.study.beanpostproessor.bean.EmbeddedService; 9 | 10 | /** 11 | * Created by Format on 2017/6/19. 12 | */ 13 | public class SimpleRegistrar implements ImportBeanDefinitionRegistrar { 14 | @Override 15 | public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) { 16 | AnnotatedGenericBeanDefinition beanDefinition = new AnnotatedGenericBeanDefinition(EmbeddedService.class); 17 | beanDefinition.getPropertyValues().add("id", "embedded_id_001"); 18 | registry.registerBeanDefinition("beanFromSimpleRegistrar", beanDefinition); 19 | } 20 | } 21 | 22 | 23 | -------------------------------------------------------------------------------- /spring-bean-post-processor/src/main/java/spring/study/beanpostproessor/processor/SimpleBeanPostProcessor.java: -------------------------------------------------------------------------------- 1 | package spring.study.beanpostproessor.processor; 2 | 3 | import org.springframework.beans.BeansException; 4 | import org.springframework.beans.factory.config.BeanPostProcessor; 5 | import org.springframework.stereotype.Component; 6 | 7 | /** 8 | * Created by Format on 2017/6/18. 9 | */ 10 | //@Component 11 | public class SimpleBeanPostProcessor implements BeanPostProcessor { 12 | 13 | private String name = "simpleServiceImpl"; 14 | 15 | @Override 16 | public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { 17 | if(beanName.equals(name)) { 18 | System.err.println("BeanPostProcessor postProcessBeforeInitialization: " + beanName + ", " + bean); 19 | } 20 | return bean; 21 | } 22 | 23 | @Override 24 | public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { 25 | if(beanName.equals(name)) { 26 | System.err.println("BeanPostProcessor postProcessAfterInitialization: " + beanName + ", " + bean); 27 | } 28 | return bean; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /springboot-refresh-context/src/main/java/spring/study/refresh/context/RefreshContextApplication.java: -------------------------------------------------------------------------------- 1 | package spring.study.refresh.context; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.context.annotation.Import; 7 | import org.springframework.context.annotation.ImportResource; 8 | import org.springframework.context.annotation.PropertySource; 9 | import org.springframework.context.annotation.PropertySources; 10 | import spring.study.refresh.context.bean.ImportService; 11 | import spring.study.refresh.context.listener.MyApplicationListener; 12 | 13 | /** 14 | * Created by Format on 2017/5/3. 15 | */ 16 | @SpringBootApplication 17 | @Import(ImportService.class) 18 | @PropertySources(@PropertySource("classpath:simple.properties")) 19 | @ImportResource("classpath:import.xml") 20 | public class RefreshContextApplication { 21 | public static void main(String[] args) { 22 | SpringApplication sa = new SpringApplication(RefreshContextApplication.class); 23 | sa.addListeners(new MyApplicationListener()); 24 | sa.run(args); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /springboot-refresh-context/src/main/java/spring/study/refresh/context/lifecycle/MyLifecycleBean.java: -------------------------------------------------------------------------------- 1 | package spring.study.refresh.context.lifecycle; 2 | 3 | import org.springframework.context.Lifecycle; 4 | import org.springframework.context.SmartLifecycle; 5 | import org.springframework.stereotype.Component; 6 | 7 | /** 8 | * Created by Format on 2017/5/8. 9 | */ 10 | @Component 11 | public class MyLifecycleBean implements SmartLifecycle { 12 | 13 | private boolean running = false; 14 | 15 | @Override 16 | public boolean isAutoStartup() { 17 | return true; 18 | } 19 | 20 | @Override 21 | public void stop(Runnable callback) { 22 | System.out.println("------ my lifecycle bean stop callback"); 23 | } 24 | 25 | @Override 26 | public void start() { 27 | running = true; 28 | System.out.println("------ my lifecycle bean start"); 29 | } 30 | 31 | @Override 32 | public void stop() { 33 | running = false; 34 | System.out.println("------ my lifecycle bean stop"); 35 | } 36 | 37 | @Override 38 | public boolean isRunning() { 39 | return running; 40 | } 41 | 42 | @Override 43 | public int getPhase() { 44 | return 0; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /log-module/src/main/java/me/format/springboot/log/aop/LogMethodInterceptor.java: -------------------------------------------------------------------------------- 1 | package me.format.springboot.log.aop; 2 | 3 | import org.aopalliance.intercept.MethodInterceptor; 4 | import org.aopalliance.intercept.MethodInvocation; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import java.util.Arrays; 9 | import java.util.List; 10 | 11 | /** 12 | * Created by format on 16/11/15. 13 | */ 14 | public class LogMethodInterceptor implements MethodInterceptor { 15 | private Logger logger = LoggerFactory.getLogger(LogMethodInterceptor.class); 16 | private List exclude; 17 | public LogMethodInterceptor(String[] exclude) { 18 | this.exclude = Arrays.asList(exclude); 19 | } 20 | @Override 21 | public Object invoke(MethodInvocation invocation) throws Throwable { 22 | String methodName = invocation.getMethod().getName(); 23 | if(exclude.contains(methodName)) { 24 | return invocation.proceed(); 25 | } 26 | long start = System.currentTimeMillis(); 27 | Object result = invocation.proceed(); 28 | long end = System.currentTimeMillis(); 29 | logger.info("====method({}), cost({}) ", methodName, (end - start)); 30 | return result; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /springboot-refresh-context/src/main/java/spring/study/refresh/context/listener/MyApplicationListener.java: -------------------------------------------------------------------------------- 1 | package spring.study.refresh.context.listener; 2 | 3 | import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.ApplicationEvent; 6 | import org.springframework.context.ApplicationListener; 7 | import org.springframework.context.event.ContextRefreshedEvent; 8 | import spring.study.refresh.context.bean.SimpleBeanInListener; 9 | 10 | /** 11 | * Created by Format on 2017/5/10. 12 | */ 13 | public class MyApplicationListener implements ApplicationListener { 14 | @Override 15 | public void onApplicationEvent(ApplicationEvent event) { 16 | if(event instanceof ContextRefreshedEvent) { 17 | ApplicationContext applicationContext = ((ContextRefreshedEvent) event).getApplicationContext(); 18 | if(applicationContext instanceof AnnotationConfigEmbeddedWebApplicationContext) { 19 | ((AnnotationConfigEmbeddedWebApplicationContext) applicationContext).getBeanFactory().registerSingleton("simpleBeanInListener", new SimpleBeanInListener()); 20 | } 21 | 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /springboot-startup/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | spring.study 8 | startup 9 | 1.0-SNAPSHOT 10 | 11 | 12 | UTF-8 13 | 1.8 14 | 15 | 16 | 17 | org.springframework.boot 18 | spring-boot-starter-parent 19 | 1.3.5.RELEASE 20 | 21 | 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-web 26 | 27 | 28 | org.projectlombok 29 | lombok 30 | 1.16.6 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /spring-custom-component-provider/src/main/java/spring/study/componentprovider/CustomComponentProviderApplication.java: -------------------------------------------------------------------------------- 1 | package spring.study.componentprovider; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.core.io.ClassPathResource; 6 | import other.pkg.OtherBean; 7 | import spring.study.componentprovider.annotation.EnableConsumer; 8 | 9 | /** 10 | * Created by Format on 2017/6/10. 11 | */ 12 | @SpringBootApplication 13 | @EnableConsumer 14 | public class CustomComponentProviderApplication { 15 | 16 | public static void main(String[] args) { 17 | 18 | 19 | 20 | SpringApplication.run( 21 | new Object[] { 22 | CustomComponentProviderApplication.class 23 | , new ClassPathResource("beans.xml") 24 | , OtherBean.class.getPackage() 25 | // , String.valueOf("other.pkg") 26 | } 27 | , args); 28 | 29 | 30 | // SpringApplication.run(CustomComponentProviderApplication.class, args); 31 | // SpringApplication sa = new SpringApplication(); 32 | // sa.run(CustomComponentProviderApplication.class, args); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /springboot-refresh-context/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | spring.study 8 | refresh-context 9 | 1.0-SNAPSHOT 10 | 11 | 12 | UTF-8 13 | 1.8 14 | 15 | 16 | 17 | org.springframework.boot 18 | spring-boot-starter-parent 19 | 1.3.5.RELEASE 20 | 21 | 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-web 26 | 27 | 28 | org.projectlombok 29 | lombok 30 | 1.16.6 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /spring-bean-post-processor/src/main/java/spring/study/beanpostproessor/runner/SimpleCommandLineRunner.java: -------------------------------------------------------------------------------- 1 | package spring.study.beanpostproessor.runner; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.boot.CommandLineRunner; 5 | import org.springframework.context.ApplicationContext; 6 | import org.springframework.stereotype.Component; 7 | import spring.study.beanpostproessor.embedded.BeanForAop; 8 | import spring.study.beanpostproessor.embedded.BeanForAsync; 9 | import spring.study.beanpostproessor.embedded.BeanForMethodValidation; 10 | 11 | /** 12 | * Created by Format on 2017/6/22. 13 | */ 14 | @Component 15 | public class SimpleCommandLineRunner implements CommandLineRunner { 16 | @Autowired 17 | private BeanForAop beanForAop; 18 | @Autowired 19 | private BeanForMethodValidation beanForMethodValidation; 20 | @Autowired 21 | private BeanForAsync beanForAsync; 22 | @Autowired 23 | private ApplicationContext applicationContext; 24 | @Override 25 | public void run(String... args) throws Exception { 26 | beanForAop.test(); 27 | beanForMethodValidation.validate("11", 15); 28 | System.out.println("start async"); 29 | beanForAsync.async(); 30 | System.out.println("end async"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /springboot-embedded-servlet-conatiner/src/main/java/spring/study/embedded/servlet/servlet/CustomServletRegistrationBean.java: -------------------------------------------------------------------------------- 1 | package spring.study.embedded.servlet.servlet; 2 | 3 | import org.springframework.boot.context.embedded.ServletRegistrationBean; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServlet; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | import java.io.IOException; 12 | 13 | /** 14 | * Created by Format on 2017/5/15. 15 | */ 16 | @Configuration 17 | public class CustomServletRegistrationBean { 18 | 19 | @Bean // 注册Servlet到Servlet容器中 20 | public ServletRegistrationBean customServlet() { 21 | return new ServletRegistrationBean(new CustomServlet(), "/custom"); 22 | } 23 | 24 | 25 | private static class CustomServlet extends HttpServlet { 26 | @Override 27 | protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 28 | resp.getWriter().write("receive by CustomServlet"); 29 | // resp.sendRedirect("https://www.github.com"); 30 | // super.service(req, resp); 31 | } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /springboot-logging-system/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | spring.study 8 | logging 9 | 1.0-SNAPSHOT 10 | 11 | 12 | UTF-8 13 | 1.8 14 | 15 | 16 | 17 | org.springframework.boot 18 | spring-boot-starter-parent 19 | 20 | 1.3.5.RELEASE 21 | 22 | 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-web 27 | 28 | 29 | org.projectlombok 30 | lombok 31 | 1.16.6 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /springboot-conditional/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | spring.study 8 | conditional 9 | 1.0-SNAPSHOT 10 | 11 | 12 | UTF-8 13 | 1.8 14 | 15 | 16 | 17 | org.springframework.boot 18 | spring-boot-starter-parent 19 | 1.3.5.RELEASE 20 | 21 | 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-web 26 | 27 | 28 | org.projectlombok 29 | lombok 30 | 1.16.6 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-test 35 | test 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /springboot-executable-jar/src/test/java/spring/study/executablejar/classloader/test/LaunchedURLClassLoaderTest.java: -------------------------------------------------------------------------------- 1 | package spring.study.executablejar.classloader.test; 2 | 3 | import org.junit.Test; 4 | import org.springframework.boot.loader.LaunchedURLClassLoader; 5 | import org.springframework.boot.loader.jar.JarFile; 6 | 7 | import java.net.URL; 8 | 9 | /** 10 | * Created by Format on 2017/5/30. 11 | */ 12 | public class LaunchedURLClassLoaderTest { 13 | 14 | @Test 15 | public void test() { 16 | try { 17 | JarFile.registerUrlProtocolHandler(); 18 | LaunchedURLClassLoader classLoader = new LaunchedURLClassLoader( 19 | new URL[] { 20 | new URL("jar:file:/Users/fangjian/Develop/gitrepository/springboot-analysis/springboot-executable-jar/target/executable-jar-1.0-SNAPSHOT.jar!/lib/spring-boot-loader-1.3.5.RELEASE.jar!/") 21 | , new URL("jar:file:/Users/fangjian/Develop/gitrepository/springboot-analysis/springboot-executable-jar/target/executable-jar-1.0-SNAPSHOT.jar!/lib/spring-boot-1.3.5.RELEASE.jar!/") 22 | }, 23 | LaunchedURLClassLoaderTest.class.getClassLoader()); 24 | 25 | // classLoader.loadClass("org.springframework.boot.loader.JarLauncher"); 26 | // classLoader.loadClass("org.springframework.boot.SpringApplication"); 27 | classLoader.loadClass("org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration"); 28 | } catch (Exception e) { 29 | e.printStackTrace(); 30 | } 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /spring-bean-post-processor/src/main/java/spring/study/beanpostproessor/processor/SimpleDestructionAwareBeanPostProcessor.java: -------------------------------------------------------------------------------- 1 | package spring.study.beanpostproessor.processor; 2 | 3 | import org.springframework.beans.BeansException; 4 | import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor; 5 | import org.springframework.stereotype.Component; 6 | 7 | /** 8 | * Created by Format on 2017/6/20. 9 | */ 10 | //@Component 11 | public class SimpleDestructionAwareBeanPostProcessor implements DestructionAwareBeanPostProcessor { 12 | 13 | private String name = "simpleServiceForDestroy"; 14 | 15 | @Override 16 | public void postProcessBeforeDestruction(Object bean, String beanName) throws BeansException { 17 | if(beanName != null && beanName.equals(name)) { 18 | System.err.println("DestructionAwareBeanPostProcessor postProcessBeforeDestruction: " + beanName + ", " + bean); 19 | } 20 | } 21 | 22 | @Override 23 | public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { 24 | if(beanName.equals(name)) { 25 | System.err.println("DestructionAwareBeanPostProcessor postProcessBeforeInitialization: " + beanName + ", " + bean); 26 | } 27 | return bean; 28 | } 29 | 30 | @Override 31 | public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { 32 | if(beanName.equals(name)) { 33 | System.err.println("DestructionAwareBeanPostProcessor postProcessAfterInitialization: " + beanName + ", " + bean); 34 | } 35 | return bean; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /springboot-environment-loader/src/main/java/spring/study/property/loader/processor/CustomBeanFactoryPostProcessor.java: -------------------------------------------------------------------------------- 1 | package spring.study.property.loader.processor; 2 | 3 | import org.springframework.beans.BeansException; 4 | import org.springframework.beans.factory.annotation.Value; 5 | import org.springframework.beans.factory.config.BeanFactoryPostProcessor; 6 | import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; 7 | import org.springframework.context.ApplicationContext; 8 | import org.springframework.context.ApplicationContextAware; 9 | import org.springframework.core.env.MapPropertySource; 10 | import org.springframework.core.env.StandardEnvironment; 11 | import org.springframework.stereotype.Component; 12 | 13 | import java.util.HashMap; 14 | import java.util.Map; 15 | 16 | /** 17 | * Created by Format on 2017/6/9. 18 | */ 19 | @Component 20 | public class CustomBeanFactoryPostProcessor implements BeanFactoryPostProcessor, ApplicationContextAware { 21 | 22 | private ApplicationContext applicationContext; 23 | 24 | @Override 25 | public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { 26 | String name = "custom"; 27 | Map map = new HashMap<>(); 28 | map.put("my.name", "processor"); 29 | ((StandardEnvironment) applicationContext.getEnvironment()).getPropertySources().addFirst(new MapPropertySource(name, map)); 30 | } 31 | 32 | @Override 33 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { 34 | this.applicationContext = applicationContext; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /springboot-factories-loader/src/test/java/spring/study/factories/loader/test/LoadTest.java: -------------------------------------------------------------------------------- 1 | package spring.study.factories.loader.test; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 6 | import org.springframework.boot.test.SpringApplicationConfiguration; 7 | import org.springframework.core.io.support.SpringFactoriesLoader; 8 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 9 | import spring.study.factories.loader.SpringFactoriesApplication; 10 | 11 | import java.io.IOException; 12 | import java.net.URL; 13 | import java.util.Enumeration; 14 | import java.util.List; 15 | 16 | /** 17 | * Created by Format on 2017/6/3. 18 | */ 19 | @RunWith(SpringJUnit4ClassRunner.class) 20 | @SpringApplicationConfiguration(classes = SpringFactoriesApplication.class) 21 | public class LoadTest { 22 | 23 | @Test 24 | public void test01() { 25 | try { 26 | Enumeration files = this.getClass().getClassLoader().getResources(SpringFactoriesLoader.FACTORIES_RESOURCE_LOCATION); 27 | 28 | while(files.hasMoreElements()) { 29 | System.out.println("=== " + files.nextElement()); 30 | } 31 | 32 | } catch (IOException e) { 33 | e.printStackTrace(); 34 | } 35 | } 36 | 37 | @Test 38 | public void test02() { 39 | List classes = SpringFactoriesLoader.loadFactoryNames(EnableAutoConfiguration.class, this.getClass().getClassLoader()); 40 | classes.forEach(clazz -> { 41 | System.out.println("==== " + clazz); 42 | }); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /springboot-only-test/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | spring.study 8 | mytest 9 | 1.0-SNAPSHOT 10 | 11 | 12 | UTF-8 13 | 1.8 14 | 15 | 16 | 17 | org.springframework.boot 18 | spring-boot-starter-parent 19 | 1.3.5.RELEASE 20 | 21 | 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-web 26 | 27 | 28 | org.projectlombok 29 | lombok 30 | 1.16.6 31 | 32 | 33 | me.format.springboot 34 | log-starter 35 | 3.0-SNAPSHOT 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-aop 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 自己总结和学习的SpringBoot源码,包括一些例子代码和文章。 2 | 3 | SpringBoot的基础概念以及使用大家可以查询一下网上的资料学习一下,这个系列主要讲解SpringBoot比较底层一点的东西。 4 | 5 | 个人认为SpringBoot是对Spring的一次再封装,这样可以让我们更方便地使用Spring进行开发。像SpringBoot内置的Servlet容器、条件注解等都是基于Spring开发出来的。 6 | 7 | 1. [SpringBoot源码分析之SpringBoot的启动过程](http://fangjian0423.github.io/2017/04/30/springboot-startup-analysis/) 8 | 2. [SpringBoot源码分析之Spring容器的refresh过程](http://fangjian0423.github.io/2017/05/10/springboot-context-refresh/) 9 | 3. [SpringBoot源码分析之条件注解的底层实现](http://fangjian0423.github.io/2017/05/16/springboot-condition-annotation/) 10 | 4. [SpringBoot源码分析之内置Servlet容器](http://fangjian0423.github.io/2017/05/22/springboot-embedded-servlet-container/) 11 | 5. [SpringBoot源码分析之SpringBoot可执行文件解析](http://fangjian0423.github.io/2017/05/31/springboot-executable-jar/) 12 | 6. [SpringBoot源码分析之工厂加载机制](http://fangjian0423.github.io/2017/06/05/springboot-factory-loading-mechanism/) 13 | 7. [SpringBoot源码分析之配置环境的构造过程](http://fangjian0423.github.io/2017/06/10/springboot-environment-analysis) 14 | 8. [SpringBoot源码分析之日志系统的构造](http://fangjian0423.github.io/2017/08/23/springboot-logging-system/) 15 | 16 | 另外也会写一些Spring和SpringBoot相关的文章。 17 | 18 | Spring: 19 | 20 | 1. [Spring自定义类扫描器](http://fangjian0423.github.io/2017/06/11/spring-custom-component-provider/) 21 | 2. [Spring类注册笔记](http://fangjian0423.github.io/2017/06/15/spring-bean-register-note/) 22 | 3. [Spring内部的BeanPostProcessor接口总结](http://fangjian0423.github.io/2017/06/20/spring-bean-post-processor/) 23 | 4. [Spring内置的BeanPostProcessor总结](http://fangjian0423.github.io/2017/06/24/spring-embedded-bean-post-processor/) 24 | 25 | SpringBoot: 26 | 27 | 1. [SpringBoot应用程序的关闭](http://fangjian0423.github.io/2017/06/28/springboot-application-exit/) 28 | -------------------------------------------------------------------------------- /spring-bean-post-processor/src/main/java/spring/study/beanpostproessor/processor/SimpleMergedBeanDefinitionPostProcessor.java: -------------------------------------------------------------------------------- 1 | package spring.study.beanpostproessor.processor; 2 | 3 | import org.springframework.beans.BeansException; 4 | import org.springframework.beans.factory.support.MergedBeanDefinitionPostProcessor; 5 | import org.springframework.beans.factory.support.RootBeanDefinition; 6 | import org.springframework.stereotype.Component; 7 | 8 | /** 9 | * Created by Format on 2017/6/20. 10 | */ 11 | //@Component 12 | public class SimpleMergedBeanDefinitionPostProcessor implements MergedBeanDefinitionPostProcessor { 13 | 14 | private String name = "simpleServiceForMerged"; 15 | 16 | @Override 17 | public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class beanType, String beanName) { 18 | if(beanName.equals(name)) { 19 | System.err.println("MergedBeanDefinitionPostProcessor postProcessMergedBeanDefinition: " + beanName + ", " + beanType + ", " + beanDefinition); 20 | } 21 | } 22 | 23 | @Override 24 | public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { 25 | if(beanName.equals(name)) { 26 | System.err.println("MergedBeanDefinitionPostProcessor postProcessBeforeInitialization: " + beanName + ", " + bean); 27 | } 28 | return bean; 29 | } 30 | 31 | @Override 32 | public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { 33 | if(beanName.equals(name)) { 34 | System.err.println("MergedBeanDefinitionPostProcessor postProcessAfterInitialization: " + beanName + ", " + bean); 35 | } 36 | return bean; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /springboot-embedded-servlet-conatiner/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | spring.study 8 | springboot-embedded-servlet-conatiner 9 | 1.0-SNAPSHOT 10 | 11 | 12 | UTF-8 13 | 1.8 14 | 15 | 16 | 17 | org.springframework.boot 18 | spring-boot-starter-parent 19 | 1.3.5.RELEASE 20 | 21 | 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-web 26 | 27 | 28 | 29 | 30 | 31 | 32 | org.projectlombok 33 | lombok 34 | 1.16.6 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-starter-test 39 | test 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /spring-bean-post-processor/src/main/java/spring/study/beanpostproessor/BeanPostProcessorApplication.java: -------------------------------------------------------------------------------- 1 | package spring.study.beanpostproessor; 2 | 3 | import org.springframework.beans.factory.config.BeanPostProcessor; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.EnableAspectJAutoProxy; 8 | import org.springframework.context.annotation.Import; 9 | import org.springframework.scheduling.annotation.EnableAsync; 10 | import org.springframework.scheduling.annotation.EnableScheduling; 11 | import org.springframework.validation.beanvalidation.BeanValidationPostProcessor; 12 | import org.springframework.validation.beanvalidation.MethodValidationPostProcessor; 13 | import spring.study.beanpostproessor.registrar.SimpleRegistrar; 14 | 15 | /** 16 | * Created by Format on 2017/6/18. 17 | */ 18 | @SpringBootApplication 19 | @Import(SimpleRegistrar.class) 20 | @EnableAspectJAutoProxy 21 | @EnableScheduling 22 | @EnableAsync 23 | public class BeanPostProcessorApplication { 24 | public static void main(String[] args) { 25 | SpringApplication.run(BeanPostProcessorApplication.class, args); 26 | } 27 | 28 | @Bean 29 | public BeanPostProcessor beanValidationPostProcessor() { 30 | BeanValidationPostProcessor processor = new BeanValidationPostProcessor(); 31 | processor.setAfterInitialization(true); 32 | return processor; 33 | } 34 | 35 | @Bean 36 | public BeanPostProcessor methodValidationPostProcessor() { 37 | MethodValidationPostProcessor processor = new MethodValidationPostProcessor(); 38 | return processor; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /log-module/src/main/java/me/format/springboot/log/autoconfigure/LogAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | package me.format.springboot.log.autoconfigure; 2 | 3 | import me.format.springboot.log.annotation.Log; 4 | import me.format.springboot.log.aop.LogMethodInterceptor; 5 | import org.aopalliance.aop.Advice; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.aop.Pointcut; 9 | import org.springframework.aop.support.AbstractPointcutAdvisor; 10 | import org.springframework.aop.support.annotation.AnnotationMatchingPointcut; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 13 | import org.springframework.context.annotation.Configuration; 14 | 15 | import javax.annotation.PostConstruct; 16 | 17 | /** 18 | * Created by format on 16/11/15. 19 | */ 20 | @Configuration 21 | @EnableConfigurationProperties(LogProperties.class) 22 | public class LogAutoConfiguration extends AbstractPointcutAdvisor { 23 | 24 | private Logger logger = LoggerFactory.getLogger(LogAutoConfiguration.class); 25 | 26 | private Pointcut pointcut; 27 | 28 | private Advice advice; 29 | 30 | @Autowired 31 | private LogProperties logProperties; 32 | 33 | @PostConstruct 34 | public void init() { 35 | logger.info("init LogAutoConfiguration start"); 36 | this.pointcut = new AnnotationMatchingPointcut(null, Log.class); 37 | this.advice = new LogMethodInterceptor(logProperties.getExcludeArr()); 38 | logger.info("init LogAutoConfiguration end"); 39 | } 40 | 41 | @Override 42 | public Pointcut getPointcut() { 43 | return this.pointcut; 44 | } 45 | 46 | @Override 47 | public Advice getAdvice() { 48 | return this.advice; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /spring-custom-component-provider/src/test/java/spring/study/componentprovider/test/SpringEmbeddedProviderTest.java: -------------------------------------------------------------------------------- 1 | package spring.study.componentprovider.test; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | import org.springframework.beans.factory.support.BeanDefinitionRegistry; 6 | import org.springframework.beans.factory.support.DefaultListableBeanFactory; 7 | import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; 8 | import org.springframework.context.annotation.AnnotatedBeanDefinitionReader; 9 | import org.springframework.context.annotation.ClassPathBeanDefinitionScanner; 10 | import org.springframework.core.io.ClassPathResource; 11 | import spring.study.componentprovider.CustomComponentProviderApplication; 12 | 13 | /** 14 | * Created by Format on 2017/6/13. 15 | */ 16 | public class SpringEmbeddedProviderTest { 17 | 18 | private BeanDefinitionRegistry beanDefinitionRegistry; 19 | 20 | @Before 21 | public void setUp() { 22 | beanDefinitionRegistry = new DefaultListableBeanFactory(); 23 | // beanDefinitionRegistry = new SimpleBeanDefinitionRegistry(); 24 | } 25 | 26 | @Test 27 | public void testAnnotatedBeanDefinitionReader() { 28 | AnnotatedBeanDefinitionReader annotatedReader = new AnnotatedBeanDefinitionReader(beanDefinitionRegistry); 29 | annotatedReader.register(CustomComponentProviderApplication.class); 30 | } 31 | 32 | @Test 33 | public void testXmlBeanDefinitionReader() { 34 | XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(beanDefinitionRegistry); 35 | xmlReader.loadBeanDefinitions(new ClassPathResource("beans.xml")); 36 | } 37 | 38 | @Test 39 | public void testClassPathBeanDefinitionScanner() { 40 | ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(beanDefinitionRegistry); 41 | scanner.scan("spring.study.componentprovider.bean"); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /springboot-refresh-context/src/main/java/spring/study/refresh/context/beanprocessor/MyBeanDefinitionRegistryPostProcessor.java: -------------------------------------------------------------------------------- 1 | package spring.study.refresh.context.beanprocessor; 2 | 3 | import org.springframework.beans.BeansException; 4 | import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition; 5 | import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; 6 | import org.springframework.beans.factory.support.BeanDefinitionRegistry; 7 | import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor; 8 | import org.springframework.core.PriorityOrdered; 9 | import org.springframework.stereotype.Component; 10 | import spring.study.refresh.context.bean.SimpleBeanInBeanDefinitionRegistryPostProcessor; 11 | import spring.study.refresh.context.bean.SimpleBeanWithDefinitionInBeanDefinitionRegistryPostProcessor; 12 | 13 | /** 14 | * Created by Format on 2017/5/9. 15 | */ 16 | @Component 17 | public class MyBeanDefinitionRegistryPostProcessor implements BeanDefinitionRegistryPostProcessor, PriorityOrdered { 18 | 19 | public MyBeanDefinitionRegistryPostProcessor() { 20 | System.out.println("------ MyBeanDefinitionRegistryPostProcessor construct"); 21 | } 22 | 23 | @Override 24 | public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException { 25 | registry.registerBeanDefinition("simpleBeanWithDefinitionInBeanDefinitionRegistryPostProcessor", 26 | new AnnotatedGenericBeanDefinition(SimpleBeanWithDefinitionInBeanDefinitionRegistryPostProcessor.class) 27 | ); 28 | } 29 | 30 | @Override 31 | public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { 32 | beanFactory.registerSingleton("simpleBeanInBeanDefinitionRegistryPostProcessor", new SimpleBeanInBeanDefinitionRegistryPostProcessor()); 33 | } 34 | 35 | @Override 36 | public int getOrder() { 37 | return 0; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /springboot-refresh-context/src/main/java/spring/study/refresh/context/beanprocessor/MyBeanFactoryPostProcessor.java: -------------------------------------------------------------------------------- 1 | package spring.study.refresh.context.beanprocessor; 2 | 3 | import org.springframework.beans.BeansException; 4 | import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition; 5 | import org.springframework.beans.factory.config.BeanDefinitionHolder; 6 | import org.springframework.beans.factory.config.BeanFactoryPostProcessor; 7 | import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; 8 | import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; 9 | import org.springframework.beans.factory.support.BeanDefinitionRegistry; 10 | import org.springframework.stereotype.Component; 11 | import spring.study.refresh.context.bean.SimpleBeanInBeanFactoryPostProcessor; 12 | import spring.study.refresh.context.bean.SimpleBeanWithDefinitionInBeanFactoryPostProcessor; 13 | 14 | /** 15 | * Created by Format on 2017/5/9. 16 | */ 17 | @Component 18 | public class MyBeanFactoryPostProcessor implements BeanFactoryPostProcessor { 19 | 20 | public MyBeanFactoryPostProcessor() { 21 | System.out.println("------ MyBeanFactoryPostProcessor construct"); 22 | } 23 | 24 | @Override 25 | public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { 26 | System.out.println("------ register custom bean in BeanFactoryPostProcessor"); 27 | beanFactory.registerSingleton("createByBeanFactoryPostProcessor", new SimpleBeanInBeanFactoryPostProcessor()); 28 | if(beanFactory instanceof BeanDefinitionRegistry) { 29 | BeanDefinitionReaderUtils.registerBeanDefinition( 30 | new BeanDefinitionHolder(new AnnotatedGenericBeanDefinition(SimpleBeanWithDefinitionInBeanFactoryPostProcessor.class), "simpleBeanWithDefinitionInBeanFactoryPostProcessor"), (BeanDefinitionRegistry) beanFactory 31 | ); 32 | } 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /springboot-environment-loader/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | spring.study 8 | environment-loader 9 | 1.0-SNAPSHOT 10 | 11 | 12 | UTF-8 13 | 1.8 14 | 15 | 16 | 17 | org.springframework.boot 18 | spring-boot-starter-parent 19 | 1.3.5.RELEASE 20 | 21 | 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-web 26 | 27 | 28 | org.projectlombok 29 | lombok 30 | 1.16.6 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-test 35 | test 36 | 37 | 38 | 39 | 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-maven-plugin 44 | 1.3.5.RELEASE 45 | 46 | 47 | 48 | repackage 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /spring-custom-component-provider/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | spring.study 8 | custom-component-provider 9 | 1.0-SNAPSHOT 10 | 11 | 12 | UTF-8 13 | 1.8 14 | 15 | 16 | 17 | org.springframework.boot 18 | spring-boot-starter-parent 19 | 1.3.5.RELEASE 20 | 21 | 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-web 26 | 27 | 28 | org.projectlombok 29 | lombok 30 | 1.16.6 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-test 35 | test 36 | 37 | 38 | 39 | 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-maven-plugin 44 | 1.3.5.RELEASE 45 | 46 | 47 | 48 | repackage 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /springboot-conditional/src/test/java/spring/study/conditional/test/TestConditionReport.java: -------------------------------------------------------------------------------- 1 | package spring.study.conditional.test; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; 7 | import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport; 8 | import org.springframework.boot.test.SpringApplicationConfiguration; 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 10 | import spring.study.conditional.ConditionalApplication; 11 | import spring.study.conditional.bean.ConditionExpressionBean; 12 | 13 | import java.util.Iterator; 14 | import java.util.Map; 15 | 16 | /** 17 | * Created by Format on 2017/5/11. 18 | */ 19 | @RunWith(SpringJUnit4ClassRunner.class) 20 | @SpringApplicationConfiguration(classes = ConditionalApplication.class) 21 | public class TestConditionReport { 22 | 23 | @Autowired 24 | private ConfigurableListableBeanFactory beanFactory; 25 | 26 | @Test 27 | public void test01() { 28 | ConditionEvaluationReport conditionEvaluationReport = beanFactory.getBean("autoConfigurationReport", ConditionEvaluationReport.class); 29 | Map result = conditionEvaluationReport.getConditionAndOutcomesBySource(); 30 | for(String key : result.keySet()) { 31 | ConditionEvaluationReport.ConditionAndOutcomes conditionAndOutcomes = result.get(key); 32 | Iterator iterator = conditionAndOutcomes.iterator(); 33 | while(iterator.hasNext()) { 34 | ConditionEvaluationReport.ConditionAndOutcome conditionAndOutcome = iterator.next(); 35 | System.out.println(key + " -- " + conditionAndOutcome.getCondition().getClass().getSimpleName() + " -- " + conditionAndOutcome.getOutcome()); 36 | } 37 | } 38 | } 39 | 40 | @Test 41 | public void test02() { 42 | ConditionExpressionBean bean = beanFactory.getBean(ConditionExpressionBean.class); 43 | System.out.println(bean); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /springboot-executable-jar/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | spring.study 8 | executable-jar 9 | 1.0-SNAPSHOT 10 | 11 | 12 | UTF-8 13 | 1.8 14 | 15 | 16 | 17 | org.springframework.boot 18 | spring-boot-starter-parent 19 | 1.3.5.RELEASE 20 | 21 | 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-web 26 | 27 | 28 | org.projectlombok 29 | lombok 30 | 1.16.6 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-loader 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-starter-test 39 | test 40 | 41 | 42 | 43 | 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-maven-plugin 48 | 1.3.5.RELEASE 49 | 50 | 51 | 52 | repackage 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /springboot-factories-loader/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | spring.study 8 | factories-loader 9 | 1.0-SNAPSHOT 10 | 11 | 12 | UTF-8 13 | 1.8 14 | 15 | 16 | 17 | org.springframework.boot 18 | spring-boot-starter-parent 19 | 1.3.5.RELEASE 20 | 21 | 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-web 26 | 27 | 28 | org.projectlombok 29 | lombok 30 | 1.16.6 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-test 35 | test 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-loader 40 | 41 | 42 | 43 | 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-maven-plugin 48 | 1.3.5.RELEASE 49 | 50 | 51 | 52 | repackage 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /spring-bean-post-processor/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | spring.study 8 | spring-bean-post-processor 9 | 1.0-SNAPSHOT 10 | 11 | 12 | UTF-8 13 | 1.8 14 | 15 | 16 | 17 | org.springframework.boot 18 | spring-boot-starter-parent 19 | 1.3.5.RELEASE 20 | 21 | 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-web 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-aop 30 | 31 | 32 | org.projectlombok 33 | lombok 34 | 1.16.6 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-starter-test 39 | test 40 | 41 | 42 | 43 | 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-maven-plugin 48 | 1.3.5.RELEASE 49 | 50 | 51 | 52 | repackage 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /springboot-embedded-servlet-conatiner/src/main/java/spring/study/embedded/servlet/controller/TestController.java: -------------------------------------------------------------------------------- 1 | package spring.study.embedded.servlet.controller; 2 | 3 | import org.springframework.beans.factory.BeanFactory; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport; 6 | import org.springframework.context.ApplicationContext; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.ResponseStatus; 11 | import org.springframework.web.bind.annotation.RestController; 12 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; 13 | 14 | import java.util.Iterator; 15 | import java.util.Map; 16 | 17 | /** 18 | * Created by Format on 2017/5/15. 19 | */ 20 | @RestController 21 | public class TestController { 22 | 23 | @Autowired 24 | private BeanFactory beanFactory; 25 | 26 | @RequestMapping("/custom") // 优先级没有servlet高 27 | public String custom() { 28 | return "custom method receive by TestController"; 29 | } 30 | 31 | @RequestMapping("/simple") // 优先级没有servlet高 32 | public String simple() { 33 | return "simple method receive by TestController"; 34 | } 35 | 36 | @RequestMapping("/test") 37 | public String test() { 38 | return beanFactory.getBean(WebMvcConfigurationSupport.class).toString(); 39 | } 40 | 41 | @RequestMapping("/conditional") 42 | public String conditonal() { 43 | StringBuilder sb = new StringBuilder(); 44 | ConditionEvaluationReport conditionEvaluationReport = beanFactory.getBean("autoConfigurationReport", ConditionEvaluationReport.class); 45 | Map result = conditionEvaluationReport.getConditionAndOutcomesBySource(); 46 | for(String key : result.keySet()) { 47 | ConditionEvaluationReport.ConditionAndOutcomes conditionAndOutcomes = result.get(key); 48 | Iterator iterator = conditionAndOutcomes.iterator(); 49 | while(iterator.hasNext()) { 50 | ConditionEvaluationReport.ConditionAndOutcome conditionAndOutcome = iterator.next(); 51 | sb.append(key + " -- " + conditionAndOutcome.getCondition().getClass().getSimpleName() + " -- " + conditionAndOutcome.getOutcome() + "
"); 52 | } 53 | } 54 | return sb.toString(); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /spring-custom-component-provider/src/main/java/spring/study/componentprovider/spring/ConsumerRegistrar.java: -------------------------------------------------------------------------------- 1 | package spring.study.componentprovider.spring; 2 | 3 | import org.springframework.beans.BeansException; 4 | import org.springframework.beans.factory.config.BeanDefinition; 5 | import org.springframework.beans.factory.support.BeanDefinitionRegistry; 6 | import org.springframework.beans.factory.support.BeanNameGenerator; 7 | import org.springframework.context.ApplicationContext; 8 | import org.springframework.context.ApplicationContextAware; 9 | import org.springframework.context.annotation.AnnotationBeanNameGenerator; 10 | import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; 11 | import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; 12 | import org.springframework.core.type.AnnotationMetadata; 13 | import org.springframework.core.type.filter.AnnotationTypeFilter; 14 | import org.springframework.core.type.filter.AssignableTypeFilter; 15 | import spring.study.componentprovider.annotation.Consumer; 16 | import spring.study.componentprovider.interfaze.IConsumer; 17 | 18 | import java.util.Set; 19 | 20 | /** 21 | * Created by Format on 2017/6/10. 22 | */ 23 | public class ConsumerRegistrar implements ImportBeanDefinitionRegistrar, ApplicationContextAware { 24 | 25 | private ApplicationContext applicationContext; 26 | 27 | private BeanNameGenerator beanNameGenerator = new AnnotationBeanNameGenerator(); 28 | 29 | @Override 30 | public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) { 31 | ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false); 32 | provider.addIncludeFilter(new AnnotationTypeFilter(Consumer.class)); 33 | provider.addIncludeFilter(new AssignableTypeFilter(IConsumer.class)); 34 | Set beanDefinitionSet = provider.findCandidateComponents("spring.study.componentprovider.bean"); 35 | 36 | for(BeanDefinition beanDefinition : beanDefinitionSet) { 37 | String beanName = beanNameGenerator.generateBeanName(beanDefinition, registry); 38 | if(!registry.containsBeanDefinition(beanName)) { 39 | registry.registerBeanDefinition(beanName, beanDefinition); 40 | registry.registerBeanDefinition("11", beanDefinition); 41 | } 42 | } 43 | 44 | } 45 | 46 | @Override 47 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { 48 | this.applicationContext = applicationContext; 49 | } 50 | } 51 | 52 | -------------------------------------------------------------------------------- /spring-bean-post-processor/src/main/java/spring/study/beanpostproessor/processor/SimpleInstantiationAwareBeanPostProcessor.java: -------------------------------------------------------------------------------- 1 | package spring.study.beanpostproessor.processor; 2 | 3 | import org.aopalliance.intercept.MethodInterceptor; 4 | import org.aopalliance.intercept.MethodInvocation; 5 | import org.springframework.aop.framework.ProxyFactory; 6 | import org.springframework.beans.BeansException; 7 | import org.springframework.beans.PropertyValues; 8 | import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor; 9 | import org.springframework.stereotype.Component; 10 | 11 | import java.beans.PropertyDescriptor; 12 | import java.util.Arrays; 13 | import java.util.Date; 14 | 15 | /** 16 | * Created by Format on 2017/6/18. 17 | */ 18 | //@Component 19 | public class SimpleInstantiationAwareBeanPostProcessor implements InstantiationAwareBeanPostProcessor { 20 | 21 | private String name = "simpleServiceImpl"; 22 | 23 | @Override 24 | public Object postProcessBeforeInstantiation(Class beanClass, String beanName) throws BeansException { 25 | if(beanName.equals(name)) { 26 | try { 27 | System.err.println("InstantiationAwareBeanPostProcessor postProcessBeforeInstantiation: " + beanName); 28 | // ProxyFactory proxyFactory = new ProxyFactory(); 29 | // proxyFactory.setInterfaces(beanClass.getInterfaces()); 30 | // proxyFactory.addAdvice(new MyMethodInterceptor()); 31 | // proxyFactory.setTarget(beanClass.newInstance()); 32 | // return proxyFactory.getProxy(); 33 | } catch (Exception e) { 34 | return null; 35 | } 36 | } 37 | return null; 38 | } 39 | 40 | @Override 41 | public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException { 42 | if(beanName.equals(name)) { 43 | System.err.println("InstantiationAwareBeanPostProcessor postProcessAfterInstantiation: " + beanName + ", " + bean); 44 | return false; 45 | } 46 | return true; 47 | } 48 | 49 | @Override 50 | public PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException { 51 | if(beanName.equals(name)) { 52 | System.err.println("InstantiationAwareBeanPostProcessor postProcessPropertyValues: " + beanName + ", " + bean + " --- " + pvs + ", " + Arrays.toString(pds)); 53 | // return null; 54 | } else if(beanName.equals("beanFromSimpleRegistrar")) { 55 | pvs.getPropertyValue("id").setConvertedValue("embedded_id_002"); 56 | } 57 | return pvs; 58 | } 59 | 60 | @Override 61 | public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { 62 | if(beanName.equals(name)) { 63 | System.err.println("InstantiationAwareBeanPostProcessor postProcessBeforeInitialization: " + beanName + ", " + bean); 64 | } 65 | return bean; 66 | } 67 | 68 | @Override 69 | public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { 70 | if(beanName.equals(name)) { 71 | System.err.println("InstantiationAwareBeanPostProcessor postProcessAfterInitialization: " + beanName + ", " + bean); 72 | } 73 | return bean; 74 | } 75 | 76 | class MyMethodInterceptor implements MethodInterceptor { 77 | @Override 78 | public Object invoke(MethodInvocation invocation) throws Throwable { 79 | System.out.println("====[proxy] start: " + new Date()); 80 | Object result = invocation.proceed(); 81 | System.out.println("====[proxy] end: " + new Date()); 82 | return result; 83 | } 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /spring-bean-post-processor/src/main/java/spring/study/beanpostproessor/processor/SimpleSmartInstantiationAwareBeanPostProcessor.java: -------------------------------------------------------------------------------- 1 | package spring.study.beanpostproessor.processor; 2 | 3 | import org.springframework.beans.BeansException; 4 | import org.springframework.beans.PropertyValues; 5 | import org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor; 6 | import org.springframework.stereotype.Component; 7 | import spring.study.beanpostproessor.bean.EmbeddedService; 8 | 9 | import java.beans.PropertyDescriptor; 10 | import java.lang.reflect.Constructor; 11 | import java.util.Arrays; 12 | 13 | /** 14 | * Created by Format on 2017/6/19. 15 | */ 16 | //@Component 17 | public class SimpleSmartInstantiationAwareBeanPostProcessor implements SmartInstantiationAwareBeanPostProcessor { 18 | 19 | private String name = "simpleServiceForS/mart"; 20 | 21 | @Override 22 | public Class predictBeanType(Class beanClass, String beanName) throws BeansException { 23 | if(beanName.equals(name)) { 24 | System.err.println("SmartInstantiationAwareBeanPostProcessor predictBeanType: " + beanName + ", " + beanClass); 25 | } 26 | return beanClass; 27 | } 28 | 29 | @Override 30 | public Constructor[] determineCandidateConstructors(Class beanClass, String beanName) throws BeansException { 31 | if(beanName.equals(name)) { 32 | System.err.println("SmartInstantiationAwareBeanPostProcessor determineCandidateConstructors: " + beanName + ", " + beanClass); 33 | try { 34 | return new Constructor[] { 35 | beanClass.getConstructor(EmbeddedService.class) 36 | }; 37 | } catch (NoSuchMethodException e) { 38 | e.printStackTrace(); 39 | } 40 | } 41 | return null; 42 | } 43 | 44 | @Override 45 | public Object getEarlyBeanReference(Object bean, String beanName) throws BeansException { 46 | if(beanName.equals("referenceA")) { 47 | System.err.println("SmartInstantiationAwareBeanPostProcessor getEarlyBeanReference: " + beanName + ", " + bean); 48 | return bean; 49 | } 50 | return bean; 51 | } 52 | 53 | @Override 54 | public Object postProcessBeforeInstantiation(Class beanClass, String beanName) throws BeansException { 55 | if(beanName.equals(name)) { 56 | System.err.println("SmartInstantiationAwareBeanPostProcessor postProcessBeforeInstantiation: " + beanName); 57 | } 58 | return null; 59 | } 60 | 61 | @Override 62 | public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException { 63 | if(beanName.equals(name)) { 64 | System.err.println("SmartInstantiationAwareBeanPostProcessor postProcessAfterInstantiation: " + beanName + ", " + bean); 65 | return false; 66 | } 67 | return true; 68 | } 69 | 70 | @Override 71 | public PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException { 72 | if(beanName.equals(name)) { 73 | System.err.println("SmartInstantiationAwareBeanPostProcessor postProcessPropertyValues: " + beanName + ", " + bean + " --- " + pvs + ", " + Arrays.toString(pds)); 74 | } 75 | return pvs; 76 | } 77 | 78 | @Override 79 | public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { 80 | if(beanName.equals(name)) { 81 | System.err.println("SmartInstantiationAwareBeanPostProcessor postProcessBeforeInitialization: " + beanName + ", " + bean); 82 | } 83 | return bean; 84 | } 85 | 86 | @Override 87 | public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { 88 | if(beanName.equals(name)) { 89 | System.err.println("SmartInstantiationAwareBeanPostProcessor postProcessAfterInitialization: " + beanName + ", " + bean); 90 | } 91 | return bean; 92 | } 93 | } 94 | --------------------------------------------------------------------------------