├── ppt
├── 1. SpringBoot整体概述.pptx
├── 10. SpringBoot整合jdbc.pptx
├── 11. SpringBoot整合MyBatis.pptx
├── 12. SpringBoot整合WebMvc.pptx
├── 13. SpringBoot整合WebFlux.pptx
├── 14. 运行SpringBoot应用.pptx
├── 2. SpringBoot的自动装配.pptx
├── 3. SpringBoot的IOC容器.pptx
├── 4. SpringBoot的核心引导-SpringApplication.pptx
├── 5. SpringBoot的AOP支持.pptx
├── 6. SpringBoot准备容器与环境.pptx
├── 7. IOC容器的刷新.pptx
├── 8. SpringBoot容器刷新扩展-嵌入式Web容器.pptx
└── 9. AOP模块的生命周期.pptx
├── springboot-00-parent
└── pom.xml
├── springboot-01-quickstart
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── linkedbear
│ │ └── springboot
│ │ └── quickstart
│ │ ├── SpringBootQuickstartApplication.java
│ │ └── controller
│ │ └── HelloController.java
│ └── resources
│ └── application.properties
├── springboot-02-ioccontainer
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── linkedbear
│ │ └── springboot
│ │ ├── SpringBootIocContainerApplication.java
│ │ └── assemble
│ │ ├── a_module
│ │ ├── TavernApplication.java
│ │ ├── anno
│ │ │ └── EnableTavern.java
│ │ ├── component
│ │ │ ├── Bar.java
│ │ │ ├── Bartender.java
│ │ │ ├── Boss.java
│ │ │ └── Waiter.java
│ │ ├── config
│ │ │ ├── BarConfiguration.java
│ │ │ ├── BartenderConfiguration.java
│ │ │ └── TavernConfiguration.java
│ │ ├── registrar
│ │ │ └── WaiterRegistrar.java
│ │ └── selector
│ │ │ ├── BarImportSelector.java
│ │ │ └── WaiterDefferedImportSelector.java
│ │ ├── b_profile
│ │ ├── TavernProfileApplication.java
│ │ ├── anno
│ │ │ └── EnableTavern.java
│ │ ├── component
│ │ │ ├── Bar.java
│ │ │ ├── Bartender.java
│ │ │ ├── Boss.java
│ │ │ └── Waiter.java
│ │ ├── config
│ │ │ ├── BarConfiguration.java
│ │ │ ├── BartenderConfiguration.java
│ │ │ ├── DataSourceConfiguration.java
│ │ │ └── TavernConfiguration.java
│ │ ├── registrar
│ │ │ └── WaiterRegistrar.java
│ │ └── selector
│ │ │ └── BarImportSelector.java
│ │ ├── c_conditional
│ │ ├── TavernConditionalApplication.java
│ │ ├── anno
│ │ │ ├── ConditionalOnBean.java
│ │ │ └── EnableTavern.java
│ │ ├── component
│ │ │ ├── Bar.java
│ │ │ ├── Bartender.java
│ │ │ ├── Boss.java
│ │ │ └── Waiter.java
│ │ ├── condition
│ │ │ ├── ExistBossCondition.java
│ │ │ └── OnBeanCondition.java
│ │ ├── config
│ │ │ ├── BarConfiguration.java
│ │ │ ├── BartenderConfiguration.java
│ │ │ └── TavernConfiguration.java
│ │ ├── registrar
│ │ │ └── WaiterRegistrar.java
│ │ └── selector
│ │ │ └── BarImportSelector.java
│ │ └── d_spi
│ │ ├── JdkSpiApplication.java
│ │ ├── SpringSpiApplication.java
│ │ └── bean
│ │ ├── DemoDao.java
│ │ ├── DemoMySQLDaoImpl.java
│ │ └── DemoOracleDaoImpl.java
│ └── resources
│ ├── META-INF
│ ├── services
│ │ └── com.linkedbear.springboot.assemble.d_spi.bean.DemoDao
│ └── spring.factories
│ ├── application-dev.properties
│ ├── application-prod.properties
│ └── application.properties
├── springboot-03-ioccontainer
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── linkedbear
│ │ └── springboot
│ │ ├── SpringBootIocContainerApplication.java
│ │ └── beandefinition
│ │ ├── AnnotationConfigBeanDefinitionConfiguration.java
│ │ ├── ComponentScanBeanDefinitionApplication.java
│ │ ├── bean
│ │ └── Person.java
│ │ └── config
│ │ └── BeanDefinitionConfiguration.java
│ └── resources
│ └── application.properties
├── springboot-04-springapplication
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── linkedbear
│ │ └── springboot
│ │ └── SpringApplicationApplication.java
│ └── resources
│ └── application.properties
├── springboot-05-aop
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── linkedbear
│ │ └── springboot
│ │ ├── SpringBootAopApplication.java
│ │ ├── aspect
│ │ └── ServiceAspect.java
│ │ └── service
│ │ └── DemoService.java
│ └── resources
│ └── application.properties
├── springboot-06-lifecycle
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── linkedbear
│ │ └── springboot
│ │ └── SpringBootLifecycleApplication.java
│ └── resources
│ └── application.properties
├── springboot-07-lifecycle
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── linkedbear
│ │ └── springboot
│ │ └── SpringBootLifecycleApplication.java
│ └── resources
│ └── application.properties
├── springboot-08-embeddedserver
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── linkedbear
│ │ └── springboot
│ │ └── EmbeddedServerApplication.java
│ └── resources
│ └── application.properties
├── springboot-09-aop-spring4
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── linkedbear
│ │ └── springboot
│ │ ├── SpringBootAopApplication.java
│ │ ├── aspect
│ │ └── ServiceAspect.java
│ │ └── service
│ │ └── DemoService.java
│ └── resources
│ └── application.properties
├── springboot-09-aop
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── linkedbear
│ │ └── springboot
│ │ ├── SpringBootAopApplication.java
│ │ ├── aspect
│ │ └── ServiceAspect.java
│ │ └── service
│ │ └── DemoService.java
│ └── resources
│ └── application.properties
├── springboot-10-jdbc
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── linkedbear
│ │ └── springboot
│ │ ├── SpringBootJdbcApplication.java
│ │ ├── dao
│ │ └── UserDao.java
│ │ ├── entity
│ │ └── User.java
│ │ └── service
│ │ ├── DeptService.java
│ │ └── UserService.java
│ └── resources
│ └── application.properties
├── springboot-11-mybatis
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── linkedbear
│ │ └── springboot
│ │ ├── MyBatisSpringBootApplication.java
│ │ ├── entity
│ │ └── User.java
│ │ ├── mapper
│ │ └── UserMapper.java
│ │ └── service
│ │ └── UserService.java
│ └── resources
│ ├── application.properties
│ └── mapper
│ └── UserMapper.xml
├── springboot-12-webmvc
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── linkedbear
│ │ └── springboot
│ │ ├── SpringBootWebMvcApplication.java
│ │ └── controller
│ │ └── HelloController.java
│ └── resources
│ └── application.properties
├── springboot-13-webflux
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── linkedbear
│ │ └── springboot
│ │ ├── SpringBootWebFluxApplication.java
│ │ ├── controller
│ │ └── WebmvcStyleController.java
│ │ ├── handler
│ │ └── HelloHandler.java
│ │ └── router
│ │ └── HelloRouterConfiguration.java
│ └── resources
│ └── application.properties
└── springboot-14-launch
├── pom.xml
└── src
└── main
├── java
└── com
│ └── linkedbear
│ └── springboot
│ ├── ServletInitializer.java
│ ├── SpringBootLaunchApplication.java
│ └── controller
│ └── GracefulTestController.java
└── resources
└── application.properties
/ppt/1. SpringBoot整体概述.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinkedBear/spring-boot-source-analysis-epubit/fd68986debcaad786549121dc18e58a87236ec81/ppt/1. SpringBoot整体概述.pptx
--------------------------------------------------------------------------------
/ppt/10. SpringBoot整合jdbc.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinkedBear/spring-boot-source-analysis-epubit/fd68986debcaad786549121dc18e58a87236ec81/ppt/10. SpringBoot整合jdbc.pptx
--------------------------------------------------------------------------------
/ppt/11. SpringBoot整合MyBatis.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinkedBear/spring-boot-source-analysis-epubit/fd68986debcaad786549121dc18e58a87236ec81/ppt/11. SpringBoot整合MyBatis.pptx
--------------------------------------------------------------------------------
/ppt/12. SpringBoot整合WebMvc.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinkedBear/spring-boot-source-analysis-epubit/fd68986debcaad786549121dc18e58a87236ec81/ppt/12. SpringBoot整合WebMvc.pptx
--------------------------------------------------------------------------------
/ppt/13. SpringBoot整合WebFlux.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinkedBear/spring-boot-source-analysis-epubit/fd68986debcaad786549121dc18e58a87236ec81/ppt/13. SpringBoot整合WebFlux.pptx
--------------------------------------------------------------------------------
/ppt/14. 运行SpringBoot应用.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinkedBear/spring-boot-source-analysis-epubit/fd68986debcaad786549121dc18e58a87236ec81/ppt/14. 运行SpringBoot应用.pptx
--------------------------------------------------------------------------------
/ppt/2. SpringBoot的自动装配.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinkedBear/spring-boot-source-analysis-epubit/fd68986debcaad786549121dc18e58a87236ec81/ppt/2. SpringBoot的自动装配.pptx
--------------------------------------------------------------------------------
/ppt/3. SpringBoot的IOC容器.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinkedBear/spring-boot-source-analysis-epubit/fd68986debcaad786549121dc18e58a87236ec81/ppt/3. SpringBoot的IOC容器.pptx
--------------------------------------------------------------------------------
/ppt/4. SpringBoot的核心引导-SpringApplication.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinkedBear/spring-boot-source-analysis-epubit/fd68986debcaad786549121dc18e58a87236ec81/ppt/4. SpringBoot的核心引导-SpringApplication.pptx
--------------------------------------------------------------------------------
/ppt/5. SpringBoot的AOP支持.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinkedBear/spring-boot-source-analysis-epubit/fd68986debcaad786549121dc18e58a87236ec81/ppt/5. SpringBoot的AOP支持.pptx
--------------------------------------------------------------------------------
/ppt/6. SpringBoot准备容器与环境.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinkedBear/spring-boot-source-analysis-epubit/fd68986debcaad786549121dc18e58a87236ec81/ppt/6. SpringBoot准备容器与环境.pptx
--------------------------------------------------------------------------------
/ppt/7. IOC容器的刷新.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinkedBear/spring-boot-source-analysis-epubit/fd68986debcaad786549121dc18e58a87236ec81/ppt/7. IOC容器的刷新.pptx
--------------------------------------------------------------------------------
/ppt/8. SpringBoot容器刷新扩展-嵌入式Web容器.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinkedBear/spring-boot-source-analysis-epubit/fd68986debcaad786549121dc18e58a87236ec81/ppt/8. SpringBoot容器刷新扩展-嵌入式Web容器.pptx
--------------------------------------------------------------------------------
/ppt/9. AOP模块的生命周期.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinkedBear/spring-boot-source-analysis-epubit/fd68986debcaad786549121dc18e58a87236ec81/ppt/9. AOP模块的生命周期.pptx
--------------------------------------------------------------------------------
/springboot-00-parent/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | org.springframework.boot
8 | spring-boot-starter-parent
9 | 2.3.11.RELEASE
10 |
11 |
12 | com.linkedbear.springboot
13 | springboot-00-parent
14 | 1.0-RELEASE
15 | pom
16 |
17 |
18 | 1.8
19 |
20 |
--------------------------------------------------------------------------------
/springboot-01-quickstart/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | springboot-00-parent
7 | com.linkedbear.springboot
8 | 1.0-RELEASE
9 | ../springboot-00-parent/pom.xml
10 |
11 | 4.0.0
12 |
13 | springboot-01-quickstart
14 |
15 |
16 | 1.8
17 |
18 |
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-web
23 |
24 |
25 |
26 | org.springframework.boot
27 | spring-boot-starter-thymeleaf
28 |
29 |
30 |
37 |
38 |
39 |
40 |
41 |
42 | org.springframework.boot
43 | spring-boot-maven-plugin
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/springboot-01-quickstart/src/main/java/com/linkedbear/springboot/quickstart/SpringBootQuickstartApplication.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.quickstart;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SpringBootQuickstartApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(SpringBootQuickstartApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/springboot-01-quickstart/src/main/java/com/linkedbear/springboot/quickstart/controller/HelloController.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.quickstart.controller;
2 |
3 | import org.springframework.web.bind.annotation.GetMapping;
4 | import org.springframework.web.bind.annotation.RestController;
5 |
6 | @RestController
7 | public class HelloController {
8 |
9 | @GetMapping("/hello")
10 | public String hello() {
11 | return "hello";
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/springboot-01-quickstart/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinkedBear/spring-boot-source-analysis-epubit/fd68986debcaad786549121dc18e58a87236ec81/springboot-01-quickstart/src/main/resources/application.properties
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | springboot-00-parent
7 | com.linkedbear.springboot
8 | 1.0-RELEASE
9 | ../springboot-00-parent/pom.xml
10 |
11 | 4.0.0
12 |
13 | springboot-02-ioccontainer
14 |
15 |
16 | 1.8
17 |
18 |
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-web
23 |
24 |
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-maven-plugin
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/SpringBootIocContainerApplication.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SpringBootIocContainerApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(SpringBootIocContainerApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/a_module/TavernApplication.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.a_module;
2 |
3 | import com.linkedbear.springboot.assemble.a_module.config.TavernConfiguration;
4 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
5 |
6 | import java.util.stream.Stream;
7 |
8 | public class TavernApplication {
9 |
10 | public static void main(String[] args) {
11 | AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(TavernConfiguration.class);
12 | Stream.of(ctx.getBeanDefinitionNames()).forEach(System.out::println);
13 | System.out.println("--------------------------");
14 | // Boss boss = ctx.getBean(Boss.class);
15 | // System.out.println(boss);
16 | // Map bartenders = ctx.getBeansOfType(Bartender.class);
17 | // bartenders.forEach((name, bartender) -> System.out.println(bartender));
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/a_module/anno/EnableTavern.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.a_module.anno;
2 |
3 | import com.linkedbear.springboot.assemble.a_module.component.Boss;
4 | import com.linkedbear.springboot.assemble.a_module.config.BartenderConfiguration;
5 | import com.linkedbear.springboot.assemble.a_module.registrar.WaiterRegistrar;
6 | import com.linkedbear.springboot.assemble.a_module.selector.BarImportSelector;
7 | import com.linkedbear.springboot.assemble.a_module.selector.WaiterDeferredImportSelector;
8 | import org.springframework.context.annotation.Import;
9 |
10 | import java.lang.annotation.Documented;
11 | import java.lang.annotation.ElementType;
12 | import java.lang.annotation.Retention;
13 | import java.lang.annotation.RetentionPolicy;
14 | import java.lang.annotation.Target;
15 |
16 | @Documented
17 | @Retention(RetentionPolicy.RUNTIME)
18 | @Target(ElementType.TYPE)
19 | @Import({Boss.class, BartenderConfiguration.class, BarImportSelector.class, WaiterRegistrar.class,
20 | WaiterDeferredImportSelector.class
21 | })
22 | public @interface EnableTavern {
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/a_module/component/Bar.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.a_module.component;
2 |
3 | /**
4 | * 吧台
5 | */
6 | public class Bar {
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/a_module/component/Bartender.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.a_module.component;
2 |
3 | /**
4 | * 调酒师
5 | */
6 | public class Bartender {
7 |
8 | private String name;
9 |
10 | public Bartender(String name) {
11 | this.name = name;
12 | }
13 |
14 | public String getName() {
15 | return name;
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/a_module/component/Boss.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.a_module.component;
2 |
3 | /**
4 | * 老板
5 | */
6 | public class Boss {
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/a_module/component/Waiter.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.a_module.component;
2 |
3 | /**
4 | * 服务员
5 | */
6 | public class Waiter {
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/a_module/config/BarConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.a_module.config;
2 |
3 | import com.linkedbear.springboot.assemble.a_module.component.Bar;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 |
7 | @Configuration
8 | public class BarConfiguration {
9 |
10 | @Bean
11 | public Bar bbbar() {
12 | return new Bar();
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/a_module/config/BartenderConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.a_module.config;
2 |
3 | import com.linkedbear.springboot.assemble.a_module.component.Bartender;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 |
7 | @Configuration
8 | public class BartenderConfiguration {
9 |
10 | @Bean
11 | public Bartender zhangxiaosan() {
12 | return new Bartender("张小三");
13 | }
14 |
15 | @Bean
16 | public Bartender zhangdasan() {
17 | return new Bartender("张大三");
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/a_module/config/TavernConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.a_module.config;
2 |
3 | import com.linkedbear.springboot.assemble.a_module.anno.EnableTavern;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | @Configuration
7 | @EnableTavern
8 | public class TavernConfiguration {
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/a_module/registrar/WaiterRegistrar.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.a_module.registrar;
2 |
3 | import com.linkedbear.springboot.assemble.a_module.component.Waiter;
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 |
9 | public class WaiterRegistrar implements ImportBeanDefinitionRegistrar {
10 |
11 | @Override
12 | public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
13 | System.out.println("WaiterRegistrar invoke ......");
14 | registry.registerBeanDefinition("waiter", new RootBeanDefinition(Waiter.class));
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/a_module/selector/BarImportSelector.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.a_module.selector;
2 |
3 | import com.linkedbear.springboot.assemble.a_module.component.Bar;
4 | import com.linkedbear.springboot.assemble.a_module.config.BarConfiguration;
5 | import org.springframework.context.annotation.ImportSelector;
6 | import org.springframework.core.type.AnnotationMetadata;
7 |
8 | public class BarImportSelector implements ImportSelector {
9 |
10 | @Override
11 | public String[] selectImports(AnnotationMetadata importingClassMetadata) {
12 | System.out.println("BarImportSelector invoke ......");
13 | return new String[] {Bar.class.getName(), BarConfiguration.class.getName()};
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/a_module/selector/WaiterDefferedImportSelector.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.a_module.selector;
2 |
3 | import com.linkedbear.springboot.assemble.a_module.component.Waiter;
4 | import org.springframework.context.annotation.DeferredImportSelector;
5 | import org.springframework.core.type.AnnotationMetadata;
6 |
7 | public class WaiterDeferredImportSelector implements DeferredImportSelector {
8 |
9 | @Override
10 | public String[] selectImports(AnnotationMetadata importingClassMetadata) {
11 | System.out.println("WaiterDeferredImportSelector invoke ......");
12 | return new String[] {Waiter.class.getName()};
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/b_profile/TavernProfileApplication.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.b_profile;
2 |
3 | import com.linkedbear.springboot.assemble.b_profile.config.TavernConfiguration;
4 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
5 |
6 | import java.util.stream.Stream;
7 |
8 | public class TavernProfileApplication {
9 |
10 | public static void main(String[] args) throws Exception {
11 | AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(TavernConfiguration.class);
12 | ctx.getEnvironment().setActiveProfiles("city");
13 | Stream.of(ctx.getBeanDefinitionNames()).forEach(System.out::println);
14 |
15 | // AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
16 | // ctx.getEnvironment().setActiveProfiles("city");
17 | // ctx.register(TavernConfiguration.class);
18 | // ctx.refresh();
19 | // Stream.of(ctx.getBeanDefinitionNames()).forEach(System.out::println);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/b_profile/anno/EnableTavern.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.b_profile.anno;
2 |
3 | import com.linkedbear.springboot.assemble.b_profile.component.Boss;
4 | import com.linkedbear.springboot.assemble.b_profile.config.BartenderConfiguration;
5 | import com.linkedbear.springboot.assemble.b_profile.registrar.WaiterRegistrar;
6 | import com.linkedbear.springboot.assemble.b_profile.selector.BarImportSelector;
7 | import org.springframework.context.annotation.Import;
8 |
9 | import java.lang.annotation.Documented;
10 | import java.lang.annotation.ElementType;
11 | import java.lang.annotation.Retention;
12 | import java.lang.annotation.RetentionPolicy;
13 | import java.lang.annotation.Target;
14 |
15 | @Documented
16 | @Retention(RetentionPolicy.RUNTIME)
17 | @Target(ElementType.TYPE)
18 | @Import({Boss.class, BartenderConfiguration.class, BarImportSelector.class, WaiterRegistrar.class})
19 | public @interface EnableTavern {
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/b_profile/component/Bar.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.b_profile.component;
2 |
3 | /**
4 | * 吧台
5 | */
6 | public class Bar {
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/b_profile/component/Bartender.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.b_profile.component;
2 |
3 | /**
4 | * 调酒师
5 | */
6 | public class Bartender {
7 |
8 | private String name;
9 |
10 | public Bartender(String name) {
11 | this.name = name;
12 | }
13 |
14 | public String getName() {
15 | return name;
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/b_profile/component/Boss.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.b_profile.component;
2 |
3 | /**
4 | * 老板
5 | */
6 | public class Boss {
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/b_profile/component/Waiter.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.b_profile.component;
2 |
3 | /**
4 | * 服务员
5 | */
6 | public class Waiter {
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/b_profile/config/BarConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.b_profile.config;
2 |
3 | import com.linkedbear.springboot.assemble.b_profile.component.Bar;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 |
7 | @Configuration
8 | public class BarConfiguration {
9 |
10 | @Bean
11 | public Bar bbbar() {
12 | return new Bar();
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/b_profile/config/BartenderConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.b_profile.config;
2 |
3 | import com.linkedbear.springboot.assemble.b_profile.component.Bartender;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 | import org.springframework.context.annotation.Profile;
7 |
8 | @Configuration
9 | @Profile("city")
10 | public class BartenderConfiguration {
11 |
12 | @Bean
13 | public Bartender zhangxiaosan() {
14 | return new Bartender("张小三");
15 | }
16 |
17 | @Bean
18 | public Bartender zhangdasan() {
19 | return new Bartender("张大三");
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/b_profile/config/DataSourceConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.b_profile.config;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.springframework.context.annotation.Profile;
6 |
7 | import javax.sql.DataSource;
8 |
9 | @Configuration
10 | public class DataSourceConfiguration {
11 |
12 | @Bean
13 | @Profile("dev")
14 | public DataSource devDataSource() {
15 | return null;
16 | }
17 |
18 | @Bean
19 | @Profile("test")
20 | public DataSource testDataSource() {
21 | return null;
22 | }
23 |
24 | @Bean
25 | @Profile("prod")
26 | public DataSource prodDataSource() {
27 | return null;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/b_profile/config/TavernConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.b_profile.config;
2 |
3 | import com.linkedbear.springboot.assemble.b_profile.anno.EnableTavern;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | @Configuration
7 | @EnableTavern
8 | public class TavernConfiguration {
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/b_profile/registrar/WaiterRegistrar.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.b_profile.registrar;
2 |
3 | import com.linkedbear.springboot.assemble.b_profile.component.Waiter;
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 |
9 | public class WaiterRegistrar implements ImportBeanDefinitionRegistrar {
10 |
11 | @Override
12 | public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
13 | registry.registerBeanDefinition("waiter", new RootBeanDefinition(Waiter.class));
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/b_profile/selector/BarImportSelector.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.b_profile.selector;
2 |
3 | import com.linkedbear.springboot.assemble.b_profile.component.Bar;
4 | import com.linkedbear.springboot.assemble.b_profile.config.BarConfiguration;
5 | import org.springframework.context.annotation.ImportSelector;
6 | import org.springframework.core.type.AnnotationMetadata;
7 |
8 | public class BarImportSelector implements ImportSelector {
9 |
10 | @Override
11 | public String[] selectImports(AnnotationMetadata importingClassMetadata) {
12 | return new String[] {Bar.class.getName(), BarConfiguration.class.getName()};
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/c_conditional/TavernConditionalApplication.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.c_conditional;
2 |
3 | import com.linkedbear.springboot.assemble.c_conditional.config.TavernConfiguration;
4 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
5 |
6 | import java.util.stream.Stream;
7 |
8 | public class TavernConditionalApplication {
9 |
10 | public static void main(String[] args) throws Exception {
11 | AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(TavernConfiguration.class);
12 | Stream.of(ctx.getBeanDefinitionNames()).forEach(System.out::println);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/c_conditional/anno/ConditionalOnBean.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.c_conditional.anno;
2 |
3 | import com.linkedbear.springboot.assemble.c_conditional.condition.OnBeanCondition;
4 | import org.springframework.context.annotation.Conditional;
5 |
6 | import java.lang.annotation.Documented;
7 | import java.lang.annotation.ElementType;
8 | import java.lang.annotation.Retention;
9 | import java.lang.annotation.RetentionPolicy;
10 | import java.lang.annotation.Target;
11 |
12 | @Documented
13 | @Retention(RetentionPolicy.RUNTIME)
14 | @Target({ElementType.TYPE, ElementType.METHOD})
15 | @Conditional(OnBeanCondition.class)
16 | public @interface ConditionalOnBean {
17 |
18 | Class>[] value() default {};
19 |
20 | String[] beanNames() default {};
21 | }
22 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/c_conditional/anno/EnableTavern.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.c_conditional.anno;
2 |
3 | import com.linkedbear.springboot.assemble.c_conditional.config.BartenderConfiguration;
4 | import com.linkedbear.springboot.assemble.c_conditional.registrar.WaiterRegistrar;
5 | import com.linkedbear.springboot.assemble.c_conditional.selector.BarImportSelector;
6 | import org.springframework.context.annotation.Import;
7 |
8 | import java.lang.annotation.Documented;
9 | import java.lang.annotation.ElementType;
10 | import java.lang.annotation.Retention;
11 | import java.lang.annotation.RetentionPolicy;
12 | import java.lang.annotation.Target;
13 |
14 | @Documented
15 | @Retention(RetentionPolicy.RUNTIME)
16 | @Target(ElementType.TYPE)
17 | @Import({BartenderConfiguration.class, BarImportSelector.class, WaiterRegistrar.class})
18 | public @interface EnableTavern {
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/c_conditional/component/Bar.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.c_conditional.component;
2 |
3 | /**
4 | * 吧台
5 | */
6 | public class Bar {
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/c_conditional/component/Bartender.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.c_conditional.component;
2 |
3 | /**
4 | * 调酒师
5 | */
6 | public class Bartender {
7 |
8 | private String name;
9 |
10 | public Bartender(String name) {
11 | this.name = name;
12 | }
13 |
14 | public String getName() {
15 | return name;
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/c_conditional/component/Boss.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.c_conditional.component;
2 |
3 | /**
4 | * 老板
5 | */
6 | public class Boss {
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/c_conditional/component/Waiter.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.c_conditional.component;
2 |
3 | /**
4 | * 服务员
5 | */
6 | public class Waiter {
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/c_conditional/condition/ExistBossCondition.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.c_conditional.condition;
2 |
3 | import com.linkedbear.springboot.assemble.c_conditional.component.Boss;
4 | import org.springframework.context.annotation.Condition;
5 | import org.springframework.context.annotation.ConditionContext;
6 | import org.springframework.core.type.AnnotatedTypeMetadata;
7 |
8 | public class ExistBossCondition implements Condition {
9 |
10 | @Override
11 | public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
12 | return context.getBeanFactory().containsBeanDefinition(Boss.class.getName());
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/c_conditional/condition/OnBeanCondition.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.c_conditional.condition;
2 |
3 | import com.linkedbear.springboot.assemble.c_conditional.anno.ConditionalOnBean;
4 | import org.springframework.context.annotation.Condition;
5 | import org.springframework.context.annotation.ConditionContext;
6 | import org.springframework.core.type.AnnotatedTypeMetadata;
7 |
8 | import java.util.Map;
9 |
10 | public class OnBeanCondition implements Condition {
11 |
12 | @Override
13 | public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
14 | Map attributes = metadata.getAnnotationAttributes(ConditionalOnBean.class.getName());
15 | // 匹配类型
16 | Class>[] classes = (Class>[]) attributes.get("value");
17 | for (Class> clazz : classes) {
18 | if (!context.getBeanFactory().containsBeanDefinition(clazz.getName())) {
19 | return false;
20 | }
21 | }
22 | // 匹配beanName
23 | String[] beanNames = (String[]) attributes.get("beanNames");
24 | for (String beanName : beanNames) {
25 | if (!context.getBeanFactory().containsBeanDefinition(beanName)) {
26 | return false;
27 | }
28 | }
29 | return true;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/c_conditional/config/BarConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.c_conditional.config;
2 |
3 | import com.linkedbear.springboot.assemble.c_conditional.anno.ConditionalOnBean;
4 | import com.linkedbear.springboot.assemble.c_conditional.component.Bar;
5 | import com.linkedbear.springboot.assemble.c_conditional.component.Boss;
6 | import org.springframework.context.annotation.Bean;
7 | import org.springframework.context.annotation.Configuration;
8 |
9 | @Configuration
10 | public class BarConfiguration {
11 |
12 | @Bean
13 | // @Conditional(ExistBossCondition.class)
14 | @ConditionalOnBean(Boss.class)
15 | public Bar bbbar() {
16 | return new Bar();
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/c_conditional/config/BartenderConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.c_conditional.config;
2 |
3 | import com.linkedbear.springboot.assemble.c_conditional.component.Bartender;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 | import org.springframework.context.annotation.Profile;
7 |
8 | @Configuration
9 | @Profile("city")
10 | public class BartenderConfiguration {
11 |
12 | @Bean
13 | public Bartender zhangxiaosan() {
14 | return new Bartender("张小三");
15 | }
16 |
17 | @Bean
18 | public Bartender zhangdasan() {
19 | return new Bartender("张大三");
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/c_conditional/config/TavernConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.c_conditional.config;
2 |
3 | import com.linkedbear.springboot.assemble.c_conditional.anno.EnableTavern;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | @Configuration
7 | @EnableTavern
8 | public class TavernConfiguration {
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/c_conditional/registrar/WaiterRegistrar.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.c_conditional.registrar;
2 |
3 | import com.linkedbear.springboot.assemble.c_conditional.component.Waiter;
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 |
9 | public class WaiterRegistrar implements ImportBeanDefinitionRegistrar {
10 |
11 | @Override
12 | public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
13 | registry.registerBeanDefinition("waiter", new RootBeanDefinition(Waiter.class));
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/c_conditional/selector/BarImportSelector.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.c_conditional.selector;
2 |
3 | import com.linkedbear.springboot.assemble.c_conditional.component.Bar;
4 | import com.linkedbear.springboot.assemble.c_conditional.config.BarConfiguration;
5 | import org.springframework.context.annotation.ImportSelector;
6 | import org.springframework.core.type.AnnotationMetadata;
7 |
8 | public class BarImportSelector implements ImportSelector {
9 |
10 | @Override
11 | public String[] selectImports(AnnotationMetadata importingClassMetadata) {
12 | return new String[] {Bar.class.getName(), BarConfiguration.class.getName()};
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/d_spi/JdkSpiApplication.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.d_spi;
2 |
3 | import com.linkedbear.spring.configuration.z_spi.bean.DemoDao;
4 |
5 | import java.util.ServiceLoader;
6 |
7 | public class JdkSpiApplication {
8 |
9 | public static void main(String[] args) throws Exception {
10 | ServiceLoader serviceLoader = ServiceLoader.load(DemoDao.class);
11 | serviceLoader.iterator().forEachRemaining(dao -> {
12 | System.out.println(dao);
13 | });
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/d_spi/SpringSpiApplication.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.d_spi;
2 |
3 | import com.linkedbear.spring.configuration.z_spi.bean.DemoDao;
4 | import org.springframework.core.io.support.SpringFactoriesLoader;
5 |
6 | import java.util.List;
7 |
8 | public class SpringSpiApplication {
9 |
10 | public static void main(String[] args) throws Exception {
11 | List demoDaos = SpringFactoriesLoader
12 | .loadFactories(DemoDao.class, SpringSpiApplication.class.getClassLoader());
13 | demoDaos.forEach(dao -> {
14 | System.out.println(dao);
15 | });
16 |
17 | System.out.println("------------------------------------------------");
18 |
19 | List daoClassNames = SpringFactoriesLoader
20 | .loadFactoryNames(DemoDao.class, SpringSpiApplication.class.getClassLoader());
21 | daoClassNames.forEach(className -> {
22 | System.out.println(className);
23 | });
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/d_spi/bean/DemoDao.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.d_spi.bean;
2 |
3 | public interface DemoDao {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/d_spi/bean/DemoMySQLDaoImpl.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.d_spi.bean;
2 |
3 | public class DemoMySQLDaoImpl implements DemoDao {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/java/com/linkedbear/springboot/assemble/d_spi/bean/DemoOracleDaoImpl.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.assemble.d_spi.bean;
2 |
3 | public class DemoOracleDaoImpl implements DemoDao {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/resources/META-INF/services/com.linkedbear.springboot.assemble.d_spi.bean.DemoDao:
--------------------------------------------------------------------------------
1 | com.linkedbear.springboot.assemble.d_spi.bean.DemoMySQLDaoImpl
2 | com.linkedbear.springboot.assemble.d_spi.bean.DemoOracleDaoImpl
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/resources/META-INF/spring.factories:
--------------------------------------------------------------------------------
1 | com.linkedbear.spring.configuration.z_spi.bean.DemoDao=\
2 | com.linkedbear.spring.configuration.z_spi.bean.DemoMySQLDaoImpl,\
3 | com.linkedbear.spring.configuration.z_spi.bean.DemoOracleDaoImpl
4 |
5 | com.linkedbear.spring.configuration.e_enablejdbc.config.EnableJdbc=\
6 | com.linkedbear.spring.configuration.e_enablejdbc.config.MySQLJdbcConfiguration,\
7 | com.linkedbear.spring.configuration.e_enablejdbc.config.OracleJdbcConfiguration,\
8 | com.linkedbear.spring.configuration.e_enablejdbc.config.H2JdbcConfiguration
9 |
10 | java.sql.Driver=\
11 | com.mysql.jdbc.Driver,\
12 | oracle.jdbc.driver.OracleDriver,\
13 | org.h2.Driver
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/resources/application-dev.properties:
--------------------------------------------------------------------------------
1 | server.port=8787
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/resources/application-prod.properties:
--------------------------------------------------------------------------------
1 | server.port=8989
--------------------------------------------------------------------------------
/springboot-02-ioccontainer/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.profiles.active=dev
--------------------------------------------------------------------------------
/springboot-03-ioccontainer/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | springboot-00-parent
7 | com.linkedbear.springboot
8 | 1.0-RELEASE
9 | ../springboot-00-parent/pom.xml
10 |
11 | 4.0.0
12 |
13 | springboot-03-ioccontainer
14 |
15 |
16 | 1.8
17 |
18 |
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-web
23 |
24 |
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-maven-plugin
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/springboot-03-ioccontainer/src/main/java/com/linkedbear/springboot/SpringBootIocContainerApplication.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SpringBootIocContainerApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(SpringBootIocContainerApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/springboot-03-ioccontainer/src/main/java/com/linkedbear/springboot/beandefinition/AnnotationConfigBeanDefinitionConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.beandefinition;
2 |
3 | import com.linkedbear.springboot.beandefinition.config.BeanDefinitionConfiguration;
4 | import org.springframework.beans.factory.config.BeanDefinition;
5 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
6 |
7 | public class AnnotationConfigBeanDefinitionConfiguration {
8 |
9 | public static void main(String[] args) {
10 | AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
11 | BeanDefinitionConfiguration.class);
12 | BeanDefinition personBeanDefinition = ctx.getBeanDefinition("person");
13 | System.out.println(personBeanDefinition);
14 | System.out.println(personBeanDefinition.getClass().getName());
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/springboot-03-ioccontainer/src/main/java/com/linkedbear/springboot/beandefinition/ComponentScanBeanDefinitionApplication.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.beandefinition;
2 |
3 | import org.springframework.beans.factory.config.BeanDefinition;
4 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
5 |
6 | public class ComponentScanBeanDefinitionApplication {
7 |
8 | public static void main(String[] args) {
9 | AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
10 | "com.linkedbear.springboot.beandefinition.bean");
11 | BeanDefinition personBeanDefinition = ctx.getBeanFactory().getBeanDefinition("person");
12 | System.out.println(personBeanDefinition);
13 | System.out.println(personBeanDefinition.getClass().getName());
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/springboot-03-ioccontainer/src/main/java/com/linkedbear/springboot/beandefinition/bean/Person.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.beandefinition.bean;
2 |
3 | import org.springframework.stereotype.Component;
4 |
5 | @Component
6 | public class Person {
7 |
8 | private String name;
9 |
10 | public String getName() {
11 | return name;
12 | }
13 |
14 | public void setName(String name) {
15 | this.name = name;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/springboot-03-ioccontainer/src/main/java/com/linkedbear/springboot/beandefinition/config/BeanDefinitionConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.beandefinition.config;
2 |
3 | import com.linkedbear.springboot.beandefinition.bean.Person;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 |
7 | @Configuration
8 | public class BeanDefinitionConfiguration {
9 |
10 | @Bean
11 | public Person person() {
12 | return new Person();
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/springboot-03-ioccontainer/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinkedBear/spring-boot-source-analysis-epubit/fd68986debcaad786549121dc18e58a87236ec81/springboot-03-ioccontainer/src/main/resources/application.properties
--------------------------------------------------------------------------------
/springboot-04-springapplication/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | springboot-00-parent
7 | com.linkedbear.springboot
8 | 1.0-RELEASE
9 | ../springboot-00-parent/pom.xml
10 |
11 | 4.0.0
12 |
13 | springboot-04-springapplication
14 |
15 |
16 | 1.8
17 |
18 |
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-web
23 |
24 |
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-maven-plugin
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/springboot-04-springapplication/src/main/java/com/linkedbear/springboot/SpringApplicationApplication.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot;
2 |
3 | import org.springframework.boot.Banner;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.WebApplicationType;
6 | import org.springframework.boot.autoconfigure.SpringBootApplication;
7 | import org.springframework.boot.builder.SpringApplicationBuilder;
8 |
9 | @SpringBootApplication
10 | public class SpringApplicationApplication {
11 |
12 | public static void main(String[] args) {
13 | SpringApplication.run(SpringApplicationApplication.class, args);
14 |
15 | // SpringApplication springApplication = new SpringApplication();
16 | // springApplication.setMainApplicationClass(SpringApplicationApplication.class);
17 | // springApplication.setBannerMode(Banner.Mode.OFF);
18 | // springApplication.run(args);
19 | //
20 | // new SpringApplicationBuilder(SpringApplicationApplication.class)
21 | // .bannerMode(Banner.Mode.OFF)
22 | // .web(WebApplicationType.NONE)
23 | // .run(args);
24 |
25 | // new SpringApplicationBuilder(SpringApplicationApplication.class).listeners(new ApplicationStartingListener()).run(args);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/springboot-04-springapplication/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinkedBear/spring-boot-source-analysis-epubit/fd68986debcaad786549121dc18e58a87236ec81/springboot-04-springapplication/src/main/resources/application.properties
--------------------------------------------------------------------------------
/springboot-05-aop/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | springboot-00-parent
7 | com.linkedbear.springboot
8 | 1.0-RELEASE
9 | ../springboot-00-parent/pom.xml
10 |
11 | 4.0.0
12 |
13 | springboot-05-aop
14 |
15 |
16 | 1.8
17 |
18 |
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-web
23 |
24 |
25 |
26 | org.springframework.boot
27 | spring-boot-starter-aop
28 |
29 |
30 |
31 |
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-maven-plugin
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/springboot-05-aop/src/main/java/com/linkedbear/springboot/SpringBootAopApplication.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot;
2 |
3 | import com.linkedbear.springboot.service.DemoService;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.context.ConfigurableApplicationContext;
7 | import org.springframework.context.annotation.EnableAspectJAutoProxy;
8 |
9 | @EnableAspectJAutoProxy
10 | @SpringBootApplication
11 | public class SpringBootAopApplication {
12 |
13 | public static void main(String[] args) {
14 | ConfigurableApplicationContext ctx = SpringApplication.run(SpringBootAopApplication.class, args);
15 | ctx.getBean(DemoService.class).save();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/springboot-05-aop/src/main/java/com/linkedbear/springboot/aspect/ServiceAspect.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.aspect;
2 |
3 | import org.aspectj.lang.annotation.Aspect;
4 | import org.aspectj.lang.annotation.Before;
5 | import org.springframework.stereotype.Component;
6 |
7 | @Aspect
8 | @Component
9 | public class ServiceAspect {
10 |
11 | @Before("execution(public * com.linkedbear.springboot.service.*.*(..))")
12 | public void beforePrint() {
13 | System.out.println("Service Aspect before advice run ......");
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/springboot-05-aop/src/main/java/com/linkedbear/springboot/service/DemoService.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.service;
2 |
3 | import org.springframework.stereotype.Service;
4 |
5 | @Service
6 | public class DemoService {
7 |
8 | public void save() {
9 | System.out.println("DemoService save run ......");
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/springboot-05-aop/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinkedBear/spring-boot-source-analysis-epubit/fd68986debcaad786549121dc18e58a87236ec81/springboot-05-aop/src/main/resources/application.properties
--------------------------------------------------------------------------------
/springboot-06-lifecycle/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | springboot-00-parent
7 | com.linkedbear.springboot
8 | 1.0-RELEASE
9 | ../springboot-00-parent/pom.xml
10 |
11 | 4.0.0
12 |
13 | springboot-06-lifecycle
14 |
15 |
16 | 1.8
17 |
18 |
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-web
23 |
24 |
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-maven-plugin
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/springboot-06-lifecycle/src/main/java/com/linkedbear/springboot/SpringBootLifecycleApplication.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SpringBootLifecycleApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(SpringBootLifecycleApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/springboot-06-lifecycle/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinkedBear/spring-boot-source-analysis-epubit/fd68986debcaad786549121dc18e58a87236ec81/springboot-06-lifecycle/src/main/resources/application.properties
--------------------------------------------------------------------------------
/springboot-07-lifecycle/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | springboot-00-parent
7 | com.linkedbear.springboot
8 | 1.0-RELEASE
9 | ../springboot-00-parent/pom.xml
10 |
11 | 4.0.0
12 |
13 | springboot-07-lifecycle
14 |
15 |
16 | 1.8
17 |
18 |
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-web
23 |
24 |
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-maven-plugin
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/springboot-07-lifecycle/src/main/java/com/linkedbear/springboot/SpringBootLifecycleApplication.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SpringBootLifecycleApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(SpringBootLifecycleApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/springboot-07-lifecycle/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinkedBear/spring-boot-source-analysis-epubit/fd68986debcaad786549121dc18e58a87236ec81/springboot-07-lifecycle/src/main/resources/application.properties
--------------------------------------------------------------------------------
/springboot-08-embeddedserver/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | springboot-00-parent
7 | com.linkedbear.springboot
8 | 1.0-RELEASE
9 | ../springboot-00-parent/pom.xml
10 |
11 | 4.0.0
12 |
13 | springboot-08-embeddedserver
14 |
15 |
16 | 1.8
17 |
18 |
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-web
23 |
24 |
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-maven-plugin
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/springboot-08-embeddedserver/src/main/java/com/linkedbear/springboot/EmbeddedServerApplication.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class EmbeddedServerApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(EmbeddedServerApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/springboot-08-embeddedserver/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinkedBear/spring-boot-source-analysis-epubit/fd68986debcaad786549121dc18e58a87236ec81/springboot-08-embeddedserver/src/main/resources/application.properties
--------------------------------------------------------------------------------
/springboot-09-aop-spring4/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | org.springframework.boot
8 | spring-boot-starter-parent
9 | 1.5.22.RELEASE
10 |
11 | com.linkedbear.springboot
12 | springboot-09-aop-spring4
13 | 1.0-RELEASE
14 |
15 |
16 |
17 | org.springframework.boot
18 | spring-boot-starter-aop
19 | 1.5.22.RELEASE
20 |
21 |
22 |
23 |
24 |
25 |
26 | org.springframework.boot
27 | spring-boot-maven-plugin
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/springboot-09-aop-spring4/src/main/java/com/linkedbear/springboot/SpringBootAopApplication.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot;
2 |
3 | import com.linkedbear.springboot.service.DemoService;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.context.ConfigurableApplicationContext;
7 | import org.springframework.context.annotation.EnableAspectJAutoProxy;
8 |
9 | @SpringBootApplication
10 | @EnableAspectJAutoProxy
11 | public class SpringBootAopApplication {
12 |
13 | public static void main(String[] args) {
14 | ConfigurableApplicationContext ctx = SpringApplication.run(SpringBootAopApplication.class, args);
15 | ctx.getBean(DemoService.class).save();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/springboot-09-aop-spring4/src/main/java/com/linkedbear/springboot/aspect/ServiceAspect.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.aspect;
2 |
3 | import org.aspectj.lang.ProceedingJoinPoint;
4 | import org.aspectj.lang.annotation.After;
5 | import org.aspectj.lang.annotation.AfterReturning;
6 | import org.aspectj.lang.annotation.AfterThrowing;
7 | import org.aspectj.lang.annotation.Around;
8 | import org.aspectj.lang.annotation.Aspect;
9 | import org.aspectj.lang.annotation.Before;
10 | import org.springframework.stereotype.Component;
11 |
12 | @Aspect
13 | @Component
14 | public class ServiceAspect {
15 |
16 | @Before("execution(public * com.linkedbear.springboot.service.*.*(..))")
17 | public void beforePrint() {
18 | System.out.println("Service Aspect before advice run ......");
19 | }
20 |
21 | @After("execution(public * com.linkedbear.springboot.service.*.*(..))")
22 | public void afterPrint() {
23 | System.out.println("Service Aspect after advice run ......");
24 | }
25 |
26 | @AfterReturning("execution(public * com.linkedbear.springboot.service.*.*(..))")
27 | public void afterReturningPrint() {
28 | System.out.println("Service Aspect afterReturning advice run ......");
29 | }
30 |
31 | @AfterThrowing("execution(public * com.linkedbear.springboot.service.*.*(..))")
32 | public void afterThrowingPrint() {
33 | System.out.println("Service Aspect afterThrowing advice run ......");
34 | }
35 |
36 | @Around("execution(public * com.linkedbear.springboot.service.*.*(..))")
37 | public Object aroundPrint(ProceedingJoinPoint joinPoint) throws Throwable {
38 | System.out.println("Service Aspect around before run ......");
39 | Object ret = joinPoint.proceed();
40 | System.out.println("Service Aspect around after run ......");
41 | return ret;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/springboot-09-aop-spring4/src/main/java/com/linkedbear/springboot/service/DemoService.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.service;
2 |
3 | import org.springframework.stereotype.Service;
4 |
5 | @Service
6 | public class DemoService {
7 |
8 | public void save() {
9 | System.out.println("DemoService save run ......");
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/springboot-09-aop-spring4/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinkedBear/spring-boot-source-analysis-epubit/fd68986debcaad786549121dc18e58a87236ec81/springboot-09-aop-spring4/src/main/resources/application.properties
--------------------------------------------------------------------------------
/springboot-09-aop/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | springboot-00-parent
7 | com.linkedbear.springboot
8 | 1.0-RELEASE
9 | ../springboot-00-parent/pom.xml
10 |
11 | 4.0.0
12 |
13 | springboot-09-aop
14 |
15 |
16 | 1.8
17 |
18 |
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-web
23 |
24 |
25 |
26 | org.springframework.boot
27 | spring-boot-starter-aop
28 |
29 |
30 |
31 |
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-maven-plugin
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/springboot-09-aop/src/main/java/com/linkedbear/springboot/SpringBootAopApplication.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot;
2 |
3 | import com.linkedbear.springboot.service.DemoService;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.context.ConfigurableApplicationContext;
7 | import org.springframework.context.annotation.EnableAspectJAutoProxy;
8 |
9 | @SpringBootApplication
10 | @EnableAspectJAutoProxy
11 | public class SpringBootAopApplication {
12 |
13 | public static void main(String[] args) {
14 | ConfigurableApplicationContext ctx = SpringApplication.run(SpringBootAopApplication.class, args);
15 | ctx.getBean(DemoService.class).save();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/springboot-09-aop/src/main/java/com/linkedbear/springboot/aspect/ServiceAspect.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.aspect;
2 |
3 | import org.aspectj.lang.ProceedingJoinPoint;
4 | import org.aspectj.lang.annotation.After;
5 | import org.aspectj.lang.annotation.AfterReturning;
6 | import org.aspectj.lang.annotation.AfterThrowing;
7 | import org.aspectj.lang.annotation.Around;
8 | import org.aspectj.lang.annotation.Aspect;
9 | import org.aspectj.lang.annotation.Before;
10 | import org.springframework.stereotype.Component;
11 |
12 | @Aspect
13 | @Component
14 | public class ServiceAspect {
15 |
16 | @Before("execution(public * com.linkedbear.springboot.service.*.*(..))")
17 | public void beforePrint() {
18 | System.out.println("Service Aspect before advice run ......");
19 | }
20 |
21 | @After("execution(public * com.linkedbear.springboot.service.*.*(..))")
22 | public void afterPrint() {
23 | System.out.println("Service Aspect after advice run ......");
24 | }
25 |
26 | @AfterReturning("execution(public * com.linkedbear.springboot.service.*.*(..))")
27 | public void afterReturningPrint() {
28 | System.out.println("Service Aspect afterReturning advice run ......");
29 | }
30 |
31 | @AfterThrowing("execution(public * com.linkedbear.springboot.service.*.*(..))")
32 | public void afterThrowingPrint() {
33 | System.out.println("Service Aspect afterThrowing advice run ......");
34 | }
35 |
36 | @Around("execution(public * com.linkedbear.springboot.service.*.*(..))")
37 | public Object aroundPrint(ProceedingJoinPoint joinPoint) throws Throwable {
38 | System.out.println("Service Aspect around before run ......");
39 | Object ret = joinPoint.proceed();
40 | System.out.println("Service Aspect around after run ......");
41 | return ret;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/springboot-09-aop/src/main/java/com/linkedbear/springboot/service/DemoService.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.service;
2 |
3 | import org.springframework.stereotype.Service;
4 |
5 | @Service
6 | public class DemoService {
7 |
8 | public void save() {
9 | System.out.println("DemoService save run ......");
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/springboot-09-aop/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinkedBear/spring-boot-source-analysis-epubit/fd68986debcaad786549121dc18e58a87236ec81/springboot-09-aop/src/main/resources/application.properties
--------------------------------------------------------------------------------
/springboot-10-jdbc/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | springboot-00-parent
7 | com.linkedbear.springboot
8 | 1.0-RELEASE
9 | ../springboot-00-parent/pom.xml
10 |
11 | 4.0.0
12 |
13 | springboot-10-jdbc
14 |
15 |
16 | 1.8
17 |
18 |
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-jdbc
23 |
24 |
25 | mysql
26 | mysql-connector-java
27 | 5.1.47
28 |
29 |
30 |
31 |
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-maven-plugin
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/springboot-10-jdbc/src/main/java/com/linkedbear/springboot/SpringBootJdbcApplication.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot;
2 |
3 | import com.linkedbear.springboot.service.DeptService;
4 | import com.linkedbear.springboot.service.UserService;
5 | import org.springframework.boot.SpringApplication;
6 | import org.springframework.boot.autoconfigure.SpringBootApplication;
7 | import org.springframework.context.ConfigurableApplicationContext;
8 | import org.springframework.transaction.annotation.EnableTransactionManagement;
9 |
10 | @SpringBootApplication
11 | @EnableTransactionManagement
12 | public class SpringBootJdbcApplication {
13 |
14 | public static void main(String[] args) {
15 | ConfigurableApplicationContext ctx = SpringApplication.run(SpringBootJdbcApplication.class, args);
16 | // UserService userService = ctx.getBean(UserService.class);
17 | // userService.test();
18 | DeptService deptService = ctx.getBean(DeptService.class);
19 | deptService.save();
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/springboot-10-jdbc/src/main/java/com/linkedbear/springboot/dao/UserDao.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.dao;
2 |
3 | import com.linkedbear.springboot.entity.User;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.jdbc.core.BeanPropertyRowMapper;
6 | import org.springframework.jdbc.core.JdbcTemplate;
7 | import org.springframework.stereotype.Repository;
8 |
9 | import java.util.List;
10 |
11 | @Repository
12 | public class UserDao {
13 |
14 | @Autowired
15 | private JdbcTemplate jdbcTemplate;
16 |
17 | public void save(User user) {
18 | jdbcTemplate.update("insert into tbl_user (name, tel) values (?, ?)", user.getName(), user.getTel());
19 | }
20 |
21 | public List findAll() {
22 | return jdbcTemplate.query("select * from tbl_user", BeanPropertyRowMapper.newInstance(User.class));
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/springboot-10-jdbc/src/main/java/com/linkedbear/springboot/entity/User.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.entity;
2 |
3 | public class User {
4 |
5 | private Integer id;
6 |
7 | private String name;
8 |
9 | private String tel;
10 |
11 | @Override
12 | public String toString() {
13 | return "User{" + "id=" + id + ", name='" + name + '\'' + ", tel='" + tel + '\'' + '}';
14 | }
15 |
16 | public Integer getId() {
17 | return id;
18 | }
19 |
20 | public void setId(Integer id) {
21 | this.id = id;
22 | }
23 |
24 | public String getName() {
25 | return name;
26 | }
27 |
28 | public void setName(String name) {
29 | this.name = name;
30 | }
31 |
32 | public String getTel() {
33 | return tel;
34 | }
35 |
36 | public void setTel(String tel) {
37 | this.tel = tel;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/springboot-10-jdbc/src/main/java/com/linkedbear/springboot/service/DeptService.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.service;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.stereotype.Service;
5 | import org.springframework.transaction.annotation.Transactional;
6 |
7 | @Service
8 | public class DeptService {
9 |
10 | @Autowired
11 | private UserService userService;
12 |
13 | @Transactional(rollbackFor = Exception.class)
14 | public void save() {
15 | System.out.println("DeptService save run ......");
16 | userService.test();
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/springboot-10-jdbc/src/main/java/com/linkedbear/springboot/service/UserService.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.service;
2 |
3 | import com.linkedbear.springboot.dao.UserDao;
4 | import com.linkedbear.springboot.entity.User;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.stereotype.Service;
7 | import org.springframework.transaction.annotation.Transactional;
8 |
9 | import java.util.List;
10 |
11 | @Service
12 | public class UserService {
13 |
14 | @Autowired
15 | private UserDao userDao;
16 |
17 | @Transactional(rollbackFor = Exception.class)
18 | public void test() {
19 | User user = new User();
20 | user.setName("test dao");
21 | user.setTel("1234567");
22 | userDao.save(user);
23 |
24 | // int i = 1 / 0;
25 |
26 | List userList = userDao.findAll();
27 | userList.forEach(System.out::println);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/springboot-10-jdbc/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver
2 | spring.datasource.url=jdbc:mysql://localhost:3306/springboot-dao?characterEncoding=utf8
3 | spring.datasource.username=root
4 | spring.datasource.password=123456
--------------------------------------------------------------------------------
/springboot-11-mybatis/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | springboot-00-parent
7 | com.linkedbear.springboot
8 | 1.0-RELEASE
9 | ../springboot-00-parent/pom.xml
10 |
11 | 4.0.0
12 |
13 | springboot-11-mybatis
14 |
15 |
16 | 1.8
17 |
18 |
19 |
20 |
21 | org.mybatis.spring.boot
22 | mybatis-spring-boot-starter
23 | 2.1.3
24 |
25 |
26 | mysql
27 | mysql-connector-java
28 | 5.1.47
29 |
30 |
31 |
32 |
33 |
34 |
35 | org.springframework.boot
36 | spring-boot-maven-plugin
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/springboot-11-mybatis/src/main/java/com/linkedbear/springboot/MyBatisSpringBootApplication.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot;
2 |
3 | import com.linkedbear.springboot.service.UserService;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.context.ConfigurableApplicationContext;
7 | import org.springframework.transaction.annotation.EnableTransactionManagement;
8 |
9 | @SpringBootApplication
10 | @EnableTransactionManagement
11 | public class MyBatisSpringBootApplication {
12 |
13 | public static void main(String[] args) {
14 | ConfigurableApplicationContext ctx = SpringApplication.run(MyBatisSpringBootApplication.class, args);
15 | UserService userService = ctx.getBean(UserService.class);
16 | userService.test();
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/springboot-11-mybatis/src/main/java/com/linkedbear/springboot/entity/User.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.entity;
2 |
3 | public class User {
4 |
5 | private Integer id;
6 |
7 | private String name;
8 |
9 | private String tel;
10 |
11 | @Override
12 | public String toString() {
13 | return "User{" + "id=" + id + ", name='" + name + '\'' + ", tel='" + tel + '\'' + '}';
14 | }
15 |
16 | public Integer getId() {
17 | return id;
18 | }
19 |
20 | public void setId(Integer id) {
21 | this.id = id;
22 | }
23 |
24 | public String getName() {
25 | return name;
26 | }
27 |
28 | public void setName(String name) {
29 | this.name = name;
30 | }
31 |
32 | public String getTel() {
33 | return tel;
34 | }
35 |
36 | public void setTel(String tel) {
37 | this.tel = tel;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/springboot-11-mybatis/src/main/java/com/linkedbear/springboot/mapper/UserMapper.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.mapper;
2 |
3 | import com.linkedbear.springboot.entity.User;
4 | import org.apache.ibatis.annotations.Mapper;
5 | import org.springframework.stereotype.Repository;
6 |
7 | import java.util.List;
8 |
9 | @Mapper
10 | @Repository
11 | public interface UserMapper {
12 |
13 | void save(User user);
14 |
15 | List findAll();
16 | }
17 |
--------------------------------------------------------------------------------
/springboot-11-mybatis/src/main/java/com/linkedbear/springboot/service/UserService.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.service;
2 |
3 | import com.linkedbear.springboot.entity.User;
4 | import com.linkedbear.springboot.mapper.UserMapper;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.stereotype.Service;
7 | import org.springframework.transaction.annotation.Transactional;
8 |
9 | import java.util.List;
10 |
11 | @Service
12 | public class UserService {
13 |
14 | @Autowired
15 | private UserMapper userMapper;
16 |
17 | @Transactional(rollbackFor = Exception.class)
18 | public void test() {
19 | User user = new User();
20 | user.setName("test mybatis");
21 | user.setTel("7654321");
22 | userMapper.save(user);
23 |
24 | // int i = 1 / 0;
25 |
26 | List userList = userMapper.findAll();
27 | userList.forEach(System.out::println);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/springboot-11-mybatis/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver
2 | spring.datasource.url=jdbc:mysql://localhost:3306/spring-dao?characterEncoding=utf8
3 | spring.datasource.username=root
4 | spring.datasource.password=123456
5 |
6 | mybatis.type-aliases-package=com.linkedbear.springboot.entity
7 | mybatis.mapper-locations=classpath:mapper/*.xml
8 | mybatis.configuration.map-underscore-to-camel-case=true
--------------------------------------------------------------------------------
/springboot-11-mybatis/src/main/resources/mapper/UserMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 | insert into tbl_user (name, tel) values (#{name}, #{tel})
8 |
9 |
10 |
13 |
--------------------------------------------------------------------------------
/springboot-12-webmvc/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | springboot-00-parent
7 | com.linkedbear.springboot
8 | 1.0-RELEASE
9 | ../springboot-00-parent/pom.xml
10 |
11 | 4.0.0
12 |
13 | springboot-12-webmvc
14 |
15 |
16 | 1.8
17 |
18 |
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-web
23 |
24 |
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-maven-plugin
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/springboot-12-webmvc/src/main/java/com/linkedbear/springboot/SpringBootWebMvcApplication.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SpringBootWebMvcApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(SpringBootWebMvcApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/springboot-12-webmvc/src/main/java/com/linkedbear/springboot/controller/HelloController.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.controller;
2 |
3 | import org.springframework.web.bind.annotation.GetMapping;
4 | import org.springframework.web.bind.annotation.RestController;
5 |
6 | @RestController
7 | public class HelloController {
8 |
9 | @GetMapping("/hello")
10 | public String hello() {
11 | return "Hello Controller";
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/springboot-12-webmvc/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinkedBear/spring-boot-source-analysis-epubit/fd68986debcaad786549121dc18e58a87236ec81/springboot-12-webmvc/src/main/resources/application.properties
--------------------------------------------------------------------------------
/springboot-13-webflux/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | springboot-00-parent
7 | com.linkedbear.springboot
8 | 1.0-RELEASE
9 | ../springboot-00-parent/pom.xml
10 |
11 | 4.0.0
12 |
13 | springboot-13-webflux
14 |
15 |
16 | 1.8
17 |
18 |
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-webflux
23 |
24 |
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-maven-plugin
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/springboot-13-webflux/src/main/java/com/linkedbear/springboot/SpringBootWebFluxApplication.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SpringBootWebFluxApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(SpringBootWebFluxApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/springboot-13-webflux/src/main/java/com/linkedbear/springboot/controller/WebmvcStyleController.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.controller;
2 |
3 | import org.springframework.web.bind.annotation.GetMapping;
4 | import org.springframework.web.bind.annotation.RestController;
5 | import reactor.core.publisher.Flux;
6 | import reactor.core.publisher.Mono;
7 |
8 | import java.util.Arrays;
9 | import java.util.List;
10 |
11 | @RestController
12 | public class WebmvcStyleController {
13 |
14 | @GetMapping("/hello")
15 | public String hello() {
16 | return "Hello WebFlux";
17 | }
18 |
19 | @GetMapping("/list")
20 | public List list() {
21 | return Arrays.asList(1, 2, 3);
22 | }
23 |
24 | @GetMapping("/hello2")
25 | public Mono hello2() {
26 | return Mono.just("Hello WebFlux");
27 | }
28 |
29 | @GetMapping("/list2")
30 | public Flux list2() {
31 | return Flux.just(1, 2, 3);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/springboot-13-webflux/src/main/java/com/linkedbear/springboot/handler/HelloHandler.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.handler;
2 |
3 | import org.springframework.http.MediaType;
4 | import org.springframework.stereotype.Component;
5 | import org.springframework.web.reactive.function.server.ServerRequest;
6 | import org.springframework.web.reactive.function.server.ServerResponse;
7 | import reactor.core.publisher.Flux;
8 | import reactor.core.publisher.Mono;
9 |
10 | @Component
11 | public class HelloHandler {
12 |
13 | public Mono hello3(ServerRequest request) {
14 | return ServerResponse.ok().contentType(MediaType.TEXT_PLAIN).body(Mono.just("Hello Handler"), String.class);
15 | }
16 |
17 | public Mono list3(ServerRequest request) {
18 | return ServerResponse.ok().contentType(MediaType.APPLICATION_JSON).body(Flux.just(1, 2, 3), Integer.class);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/springboot-13-webflux/src/main/java/com/linkedbear/springboot/router/HelloRouterConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.router;
2 |
3 | import com.linkedbear.springboot.handler.HelloHandler;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 | import org.springframework.http.MediaType;
8 | import org.springframework.web.reactive.function.server.RouterFunction;
9 | import org.springframework.web.reactive.function.server.RouterFunctions;
10 | import org.springframework.web.reactive.function.server.ServerResponse;
11 |
12 | import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
13 | import static org.springframework.web.reactive.function.server.RequestPredicates.accept;
14 |
15 | @Configuration(proxyBeanMethods = false)
16 | public class HelloRouterConfiguration {
17 |
18 | @Autowired
19 | private HelloHandler helloHandler;
20 |
21 | @Bean
22 | public RouterFunction helloRouter() {
23 | return RouterFunctions.route(GET("/hello3").and(accept(MediaType.TEXT_PLAIN)), helloHandler::hello3)
24 | .andRoute(GET("/list3").and(accept(MediaType.APPLICATION_JSON)), helloHandler::list3);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/springboot-13-webflux/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinkedBear/spring-boot-source-analysis-epubit/fd68986debcaad786549121dc18e58a87236ec81/springboot-13-webflux/src/main/resources/application.properties
--------------------------------------------------------------------------------
/springboot-14-launch/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | springboot-00-parent
7 | com.linkedbear.springboot
8 | 1.0-RELEASE
9 | ../springboot-00-parent/pom.xml
10 |
11 | 4.0.0
12 | war
13 |
14 | springboot-14-launch
15 |
16 |
17 | 1.8
18 |
19 |
20 |
21 |
22 | org.springframework.boot
23 | spring-boot-starter-web
24 |
25 |
26 | org.springframework.boot
27 | spring-boot-starter-tomcat
28 | provided
29 |
30 |
31 |
32 | org.springframework.boot
33 | spring-boot-loader
34 |
35 |
36 |
37 | org.springframework.boot
38 | spring-boot-loader-tools
39 |
40 |
41 |
42 |
43 |
44 |
45 | org.springframework.boot
46 | spring-boot-maven-plugin
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/springboot-14-launch/src/main/java/com/linkedbear/springboot/ServletInitializer.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot;
2 |
3 | import org.springframework.boot.builder.SpringApplicationBuilder;
4 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
5 |
6 | public class ServletInitializer extends SpringBootServletInitializer {
7 |
8 | @Override
9 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
10 | return application.sources(SpringBootLaunchApplication.class);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/springboot-14-launch/src/main/java/com/linkedbear/springboot/SpringBootLaunchApplication.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.context.ConfigurableApplicationContext;
6 |
7 | import java.util.Scanner;
8 |
9 | @SpringBootApplication
10 | public class SpringBootLaunchApplication {
11 |
12 | public static void main(String[] args) {
13 | ConfigurableApplicationContext ctx = SpringApplication.run(SpringBootLaunchApplication.class, args);
14 |
15 | Scanner scanner = new Scanner(System.in);
16 | while (true) {
17 | String input = scanner.nextLine();
18 | if ("exit".equals(input)) {
19 | break;
20 | }
21 | }
22 |
23 | SpringApplication.exit(ctx);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/springboot-14-launch/src/main/java/com/linkedbear/springboot/controller/GracefulTestController.java:
--------------------------------------------------------------------------------
1 | package com.linkedbear.springboot.controller;
2 |
3 | import org.springframework.web.bind.annotation.GetMapping;
4 | import org.springframework.web.bind.annotation.RestController;
5 |
6 | import java.util.concurrent.TimeUnit;
7 |
8 | @RestController
9 | public class GracefulTestController {
10 |
11 | @GetMapping("/test")
12 | public String test() throws Exception {
13 | System.out.println(System.currentTimeMillis());
14 | TimeUnit.SECONDS.sleep(10);
15 | System.out.println(System.currentTimeMillis());
16 | return "success";
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/springboot-14-launch/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | server.shutdown=graceful
2 | spring.lifecycle.timeout-per-shutdown-phase=30s
--------------------------------------------------------------------------------