Out-of-the-box implementations are available for JDK dynamic proxies 8 | * and for CGLIB proxies, as applied by DefaultAopProxyFactory 9 | * 10 | * AOP 代理的抽象 11 | * 12 | *
13 | * 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获!
14 | * 公众号:bugstack虫洞栈
15 | * Create by 小傅哥(fustack)
16 | */
17 | public interface AopProxy {
18 |
19 | Object getProxy();
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/spring-step-11/src/main/java/cn/bugstack/springframework/beans/BeansException.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description 定义 Bean 异常
9 | * @date 2022/3/7
10 | *
11 | *
12 | */
13 | public class BeansException extends RuntimeException{
14 |
15 | public BeansException(String msg) {
16 | super(msg);
17 | }
18 |
19 | public BeansException(String msg, Throwable cause) {
20 | super(msg, cause);
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/spring-step-11/src/main/java/cn/bugstack/springframework/beans/factory/Aware.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description 标记类接口,实现该接口可以被Spring容器感知
9 | * @date 2022/3/11
10 | * /CodeDesignTutorials
11 | *
12 | */
13 | public interface Aware {
14 | }
15 |
--------------------------------------------------------------------------------
/spring-step-11/src/main/java/cn/bugstack/springframework/beans/factory/BeanClassLoaderAware.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description Callback that allows a bean to be aware of the bean
9 | * {@link ClassLoader class loader}; that is, the class loader used by the
10 | * present bean factory to load bean classes.
11 | * @date 2022/3/11
12 | * /CodeDesignTutorials
13 | *
14 | */
15 | public interface BeanClassLoaderAware extends Aware {
16 |
17 | void setBeanClassLoader(ClassLoader classLoader);
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/spring-step-11/src/main/java/cn/bugstack/springframework/beans/factory/BeanFactoryAware.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | import cn.bugstack.springframework.beans.BeansException;
4 |
5 | /**
6 | *
7 | *
8 | *
9 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
10 | * @description 实现此接口,既能感知到所属的 BeanFactory
11 | * @date 2022/3/11
12 | * /CodeDesignTutorials
13 | *
14 | */
15 | public interface BeanFactoryAware extends Aware {
16 |
17 | void setBeanFactory(BeanFactory beanFactory) throws BeansException;
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/spring-step-11/src/main/java/cn/bugstack/springframework/beans/factory/HierarchicalBeanFactory.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description Sub-interface implemented by bean factories that can be part
9 | * of a hierarchy.
10 | * @date 2022/3/9
11 | * /CodeDesignTutorials
12 | *
13 | */
14 | public interface HierarchicalBeanFactory extends BeanFactory {
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/spring-step-11/src/main/java/cn/bugstack/springframework/beans/factory/InitializingBean.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description 实现此接口的 Bean 对象,会在 BeanFactory 设置属性后作出相应的处理,如:执行自定义初始化,或者仅仅检查是否设置了所有强制属性。
9 | * @date 2022/3/10
10 | * /CodeDesignTutorials
11 | *
12 | */
13 | public interface InitializingBean {
14 |
15 | /**
16 | * Bean 处理了属性填充后调用
17 | *
18 | * @throws Exception
19 | */
20 | void afterPropertiesSet() throws Exception;
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/spring-step-11/src/main/java/cn/bugstack/springframework/beans/factory/config/BeanReference.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory.config;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description Bean 引用
9 | * @date 2022/3/9
10 | * /CodeDesignTutorials
11 | *
12 | */
13 | public class BeanReference {
14 |
15 | private final String beanName;
16 |
17 | public BeanReference(String beanName) {
18 | this.beanName = beanName;
19 | }
20 |
21 | public String getBeanName() {
22 | return beanName;
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/spring-step-11/src/main/java/cn/bugstack/springframework/beans/factory/config/SingletonBeanRegistry.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory.config;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description 单例 Bean 注册表
9 | * @date 2022/03/07
10 | *
11 | *
12 | */
13 | public interface SingletonBeanRegistry {
14 |
15 | /**
16 | * 返回在给定名称下注册的(原始)单例对象。
17 | * @param beanName 要查找的bean的名称
18 | * @return 返回注册的单例对象
19 | */
20 | Object getSingleton(String beanName);
21 |
22 | void registerSingleton(String beanName, Object singletonObject);
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/spring-step-11/src/main/java/cn/bugstack/springframework/context/ApplicationContextAware.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.context;
2 |
3 | import cn.bugstack.springframework.beans.BeansException;
4 | import cn.bugstack.springframework.beans.factory.Aware;
5 |
6 | /**
7 | *
8 | *
9 | *
10 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
11 | * @description 实现此接口,既能感知到所属的 ApplicationContext
12 | * @date 2022/3/11
13 | * /CodeDesignTutorials
14 | *
15 | */
16 | public interface ApplicationContextAware extends Aware {
17 |
18 | void setApplicationContext(ApplicationContext applicationContext) throws BeansException;
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/spring-step-11/src/main/java/cn/bugstack/springframework/core/io/Resource.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.core.io;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 |
6 | /**
7 | *
8 | *
9 | *
10 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
11 | * @description 资源处理接口
12 | * @date 2022/3/9
13 | *
14 | *
15 | */
16 | public interface Resource {
17 |
18 | InputStream getInputStream() throws IOException;
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/spring-step-11/src/main/java/cn/bugstack/springframework/core/io/ResourceLoader.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.core.io;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description 资源加载器
9 | * @date 2022/3/9
10 | *
11 | *
12 | */
13 | public interface ResourceLoader {
14 |
15 | /**
16 | * Pseudo URL prefix for loading from the class path: "classpath:"
17 | */
18 | String CLASSPATH_URL_PREFIX = "classpath:";
19 |
20 | Resource getResource(String location);
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/spring-step-11/src/test/java/cn/bugstack/springframework/test/bean/IUserService.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.test.bean;
2 |
3 | public interface IUserService {
4 |
5 | String queryUserInfo();
6 |
7 | String register(String userName);
8 | }
9 |
--------------------------------------------------------------------------------
/spring-step-11/src/test/resources/spring.xml:
--------------------------------------------------------------------------------
1 |
2 |
Out-of-the-box implementations are available for JDK dynamic proxies 8 | * and for CGLIB proxies, as applied by DefaultAopProxyFactory 9 | * 10 | * AOP 代理的抽象 11 | * 12 | *
13 | * 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获! 14 | * 公众号:bugstack虫洞栈 15 | * Create by 小傅哥(fustack) 16 | */ 17 | public interface AopProxy { 18 | 19 | Object getProxy(); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /spring-step-12/src/main/java/cn/bugstack/springframework/beans/BeansException.java: -------------------------------------------------------------------------------- 1 | package cn.bugstack.springframework.beans; 2 | 3 | /** 4 | * 5 | * 6 | * 7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring 8 | * @description 定义 Bean 异常 9 | * @date 2022/3/7 10 | * 11 | * 12 | */ 13 | public class BeansException extends RuntimeException{ 14 | 15 | public BeansException(String msg) { 16 | super(msg); 17 | } 18 | 19 | public BeansException(String msg, Throwable cause) { 20 | super(msg, cause); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /spring-step-12/src/main/java/cn/bugstack/springframework/beans/factory/Aware.java: -------------------------------------------------------------------------------- 1 | package cn.bugstack.springframework.beans.factory; 2 | 3 | /** 4 | * 5 | * 6 | * 7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring 8 | * @description 标记类接口,实现该接口可以被Spring容器感知 9 | * @date 2022/3/11 10 | * /CodeDesignTutorials 11 | * 12 | */ 13 | public interface Aware { 14 | } 15 | -------------------------------------------------------------------------------- /spring-step-12/src/main/java/cn/bugstack/springframework/beans/factory/BeanClassLoaderAware.java: -------------------------------------------------------------------------------- 1 | package cn.bugstack.springframework.beans.factory; 2 | 3 | /** 4 | * 5 | * 6 | * 7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring 8 | * @description Callback that allows a bean to be aware of the bean 9 | * {@link ClassLoader class loader}; that is, the class loader used by the 10 | * present bean factory to load bean classes. 11 | * @date 2022/3/11 12 | * /CodeDesignTutorials 13 | * 14 | */ 15 | public interface BeanClassLoaderAware extends Aware { 16 | 17 | void setBeanClassLoader(ClassLoader classLoader); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /spring-step-12/src/main/java/cn/bugstack/springframework/beans/factory/BeanFactoryAware.java: -------------------------------------------------------------------------------- 1 | package cn.bugstack.springframework.beans.factory; 2 | 3 | import cn.bugstack.springframework.beans.BeansException; 4 | 5 | /** 6 | * 7 | * 8 | * 9 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring 10 | * @description 实现此接口,既能感知到所属的 BeanFactory 11 | * @date 2022/3/11 12 | * /CodeDesignTutorials 13 | * 14 | */ 15 | public interface BeanFactoryAware extends Aware { 16 | 17 | void setBeanFactory(BeanFactory beanFactory) throws BeansException; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /spring-step-12/src/main/java/cn/bugstack/springframework/beans/factory/HierarchicalBeanFactory.java: -------------------------------------------------------------------------------- 1 | package cn.bugstack.springframework.beans.factory; 2 | 3 | /** 4 | * 5 | * 6 | * 7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring 8 | * @description Sub-interface implemented by bean factories that can be part 9 | * of a hierarchy. 10 | * @date 2022/3/9 11 | * /CodeDesignTutorials 12 | * 13 | */ 14 | public interface HierarchicalBeanFactory extends BeanFactory { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-step-12/src/main/java/cn/bugstack/springframework/beans/factory/InitializingBean.java: -------------------------------------------------------------------------------- 1 | package cn.bugstack.springframework.beans.factory; 2 | 3 | /** 4 | * 5 | * 6 | * 7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring 8 | * @description 实现此接口的 Bean 对象,会在 BeanFactory 设置属性后作出相应的处理,如:执行自定义初始化,或者仅仅检查是否设置了所有强制属性。 9 | * @date 2022/3/10 10 | * /CodeDesignTutorials 11 | * 12 | */ 13 | public interface InitializingBean { 14 | 15 | /** 16 | * Bean 处理了属性填充后调用 17 | * 18 | * @throws Exception 19 | */ 20 | void afterPropertiesSet() throws Exception; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /spring-step-12/src/main/java/cn/bugstack/springframework/beans/factory/config/BeanReference.java: -------------------------------------------------------------------------------- 1 | package cn.bugstack.springframework.beans.factory.config; 2 | 3 | /** 4 | * 5 | * 6 | * 7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring 8 | * @description Bean 引用 9 | * @date 2022/3/9 10 | * /CodeDesignTutorials 11 | * 12 | */ 13 | public class BeanReference { 14 | 15 | private final String beanName; 16 | 17 | public BeanReference(String beanName) { 18 | this.beanName = beanName; 19 | } 20 | 21 | public String getBeanName() { 22 | return beanName; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /spring-step-12/src/main/java/cn/bugstack/springframework/beans/factory/config/SingletonBeanRegistry.java: -------------------------------------------------------------------------------- 1 | package cn.bugstack.springframework.beans.factory.config; 2 | 3 | /** 4 | * 5 | * 6 | * 7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring 8 | * @description 单例 Bean 注册表 9 | * @date 2022/03/07 10 | * 11 | * 12 | */ 13 | public interface SingletonBeanRegistry { 14 | 15 | /** 16 | * 返回在给定名称下注册的(原始)单例对象。 17 | * @param beanName 要查找的bean的名称 18 | * @return 返回注册的单例对象 19 | */ 20 | Object getSingleton(String beanName); 21 | 22 | void registerSingleton(String beanName, Object singletonObject); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /spring-step-12/src/main/java/cn/bugstack/springframework/context/ApplicationContextAware.java: -------------------------------------------------------------------------------- 1 | package cn.bugstack.springframework.context; 2 | 3 | import cn.bugstack.springframework.beans.BeansException; 4 | import cn.bugstack.springframework.beans.factory.Aware; 5 | 6 | /** 7 | * 8 | * 9 | * 10 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring 11 | * @description 实现此接口,既能感知到所属的 ApplicationContext 12 | * @date 2022/3/11 13 | * /CodeDesignTutorials 14 | * 15 | */ 16 | public interface ApplicationContextAware extends Aware { 17 | 18 | void setApplicationContext(ApplicationContext applicationContext) throws BeansException; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /spring-step-12/src/main/java/cn/bugstack/springframework/core/io/Resource.java: -------------------------------------------------------------------------------- 1 | package cn.bugstack.springframework.core.io; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | /** 7 | * 8 | * 9 | * 10 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring 11 | * @description 资源处理接口 12 | * @date 2022/3/9 13 | * 14 | * 15 | */ 16 | public interface Resource { 17 | 18 | InputStream getInputStream() throws IOException; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /spring-step-12/src/main/java/cn/bugstack/springframework/core/io/ResourceLoader.java: -------------------------------------------------------------------------------- 1 | package cn.bugstack.springframework.core.io; 2 | 3 | /** 4 | * 5 | * 6 | * 7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring 8 | * @description 资源加载器 9 | * @date 2022/3/9 10 | * 11 | * 12 | */ 13 | public interface ResourceLoader { 14 | 15 | /** 16 | * Pseudo URL prefix for loading from the class path: "classpath:" 17 | */ 18 | String CLASSPATH_URL_PREFIX = "classpath:"; 19 | 20 | Resource getResource(String location); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /spring-step-12/src/test/java/cn/bugstack/springframework/test/bean/IUserService.java: -------------------------------------------------------------------------------- 1 | package cn.bugstack.springframework.test.bean; 2 | 3 | public interface IUserService { 4 | 5 | String queryUserInfo(); 6 | 7 | String register(String userName); 8 | } 9 | -------------------------------------------------------------------------------- /spring-step-12/src/test/java/cn/bugstack/springframework/test/bean/UserServiceBeforeAdvice.java: -------------------------------------------------------------------------------- 1 | package cn.bugstack.springframework.test.bean; 2 | 3 | import cn.bugstack.springframework.aop.MethodBeforeAdvice; 4 | 5 | import java.lang.reflect.Method; 6 | 7 | public class UserServiceBeforeAdvice implements MethodBeforeAdvice { 8 | 9 | @Override 10 | public void before(Method method, Object[] args, Object target) throws Throwable { 11 | System.out.println("拦截方法:" + method.getName()); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /spring-step-13/src/main/java/cn/bugstack/springframework/aop/BeforeAdvice.java: -------------------------------------------------------------------------------- 1 | package cn.bugstack.springframework.aop; 2 | 3 | import org.aopalliance.aop.Advice; 4 | 5 | /** 6 | * 7 | * 8 | * 9 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring 10 | * @description Common marker interface for before advice, such as {@link MethodBeforeAdvice}. 11 | * @date 2022/3/14 12 | * /CodeDesignTutorials 13 | * 14 | */ 15 | public interface BeforeAdvice extends Advice { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /spring-step-13/src/main/java/cn/bugstack/springframework/aop/ClassFilter.java: -------------------------------------------------------------------------------- 1 | package cn.bugstack.springframework.aop; 2 | 3 | /** 4 | * Filter that restricts matching of a pointcut or introduction to 5 | * a given set of target classes. 6 | * 7 | * 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获! 8 | * 公众号:bugstack虫洞栈 9 | * Create by 小傅哥(fustack) 10 | */ 11 | public interface ClassFilter { 12 | 13 | /** 14 | * Should the pointcut apply to the given interface or target class? 15 | * @param clazz the candidate target class 16 | * @return whether the advice should apply to the given target class 17 | */ 18 | boolean matches(Class> clazz); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /spring-step-13/src/main/java/cn/bugstack/springframework/aop/MethodMatcher.java: -------------------------------------------------------------------------------- 1 | package cn.bugstack.springframework.aop; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | /** 6 | * Part of a {@link Pointcut}: Checks whether the target method is eligible for advice. 7 | * 8 | * 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获! 9 | * 公众号:bugstack虫洞栈 10 | * Create by 小傅哥(fustack) 11 | */ 12 | public interface MethodMatcher { 13 | 14 | /** 15 | * Perform static checking whether the given method matches. If this 16 | * @return whether or not this method matches statically 17 | */ 18 | boolean matches(Method method, Class> targetClass); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /spring-step-13/src/main/java/cn/bugstack/springframework/aop/PointcutAdvisor.java: -------------------------------------------------------------------------------- 1 | package cn.bugstack.springframework.aop; 2 | 3 | /** 4 | * 5 | * 6 | * 7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring 8 | * @description Superinterface for all Advisors that are driven by a pointcut. 9 | * This covers nearly all advisors except introduction advisors, 10 | * for which method-level matching doesn't apply. 11 | * @date 2022/3/14 12 | * /CodeDesignTutorials 13 | * 14 | */ 15 | public interface PointcutAdvisor extends Advisor { 16 | 17 | /** 18 | * Get the Pointcut that drives this advisor. 19 | */ 20 | Pointcut getPointcut(); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /spring-step-13/src/main/java/cn/bugstack/springframework/aop/framework/AopProxy.java: -------------------------------------------------------------------------------- 1 | package cn.bugstack.springframework.aop.framework; 2 | 3 | /** 4 | * Delegate interface for a configured AOP proxy, allowing for the creation 5 | * of actual proxy objects. 6 | * 7 | *
Out-of-the-box implementations are available for JDK dynamic proxies 8 | * and for CGLIB proxies, as applied by DefaultAopProxyFactory 9 | * 10 | * AOP 代理的抽象 11 | * 12 | *
13 | * 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获!
14 | * 公众号:bugstack虫洞栈
15 | * Create by 小傅哥(fustack)
16 | */
17 | public interface AopProxy {
18 |
19 | Object getProxy();
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/spring-step-13/src/main/java/cn/bugstack/springframework/beans/BeansException.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description 定义 Bean 异常
9 | * @date 2022/3/7
10 | *
11 | *
12 | */
13 | public class BeansException extends RuntimeException{
14 |
15 | public BeansException(String msg) {
16 | super(msg);
17 | }
18 |
19 | public BeansException(String msg, Throwable cause) {
20 | super(msg, cause);
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/spring-step-13/src/main/java/cn/bugstack/springframework/beans/factory/Aware.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description 标记类接口,实现该接口可以被Spring容器感知
9 | * @date 2022/3/11
10 | * /CodeDesignTutorials
11 | *
12 | */
13 | public interface Aware {
14 | }
15 |
--------------------------------------------------------------------------------
/spring-step-13/src/main/java/cn/bugstack/springframework/beans/factory/BeanClassLoaderAware.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description Callback that allows a bean to be aware of the bean
9 | * {@link ClassLoader class loader}; that is, the class loader used by the
10 | * present bean factory to load bean classes.
11 | * @date 2022/3/11
12 | * /CodeDesignTutorials
13 | *
14 | */
15 | public interface BeanClassLoaderAware extends Aware {
16 |
17 | void setBeanClassLoader(ClassLoader classLoader);
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/spring-step-13/src/main/java/cn/bugstack/springframework/beans/factory/BeanFactoryAware.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | import cn.bugstack.springframework.beans.BeansException;
4 |
5 | /**
6 | *
7 | *
8 | *
9 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
10 | * @description 实现此接口,既能感知到所属的 BeanFactory
11 | * @date 2022/3/11
12 | * /CodeDesignTutorials
13 | *
14 | */
15 | public interface BeanFactoryAware extends Aware {
16 |
17 | void setBeanFactory(BeanFactory beanFactory) throws BeansException;
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/spring-step-13/src/main/java/cn/bugstack/springframework/beans/factory/HierarchicalBeanFactory.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description Sub-interface implemented by bean factories that can be part
9 | * of a hierarchy.
10 | * @date 2022/3/9
11 | * /CodeDesignTutorials
12 | *
13 | */
14 | public interface HierarchicalBeanFactory extends BeanFactory {
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/spring-step-13/src/main/java/cn/bugstack/springframework/beans/factory/InitializingBean.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description 实现此接口的 Bean 对象,会在 BeanFactory 设置属性后作出相应的处理,如:执行自定义初始化,或者仅仅检查是否设置了所有强制属性。
9 | * @date 2022/3/10
10 | * /CodeDesignTutorials
11 | *
12 | */
13 | public interface InitializingBean {
14 |
15 | /**
16 | * Bean 处理了属性填充后调用
17 | *
18 | * @throws Exception
19 | */
20 | void afterPropertiesSet() throws Exception;
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/spring-step-13/src/main/java/cn/bugstack/springframework/beans/factory/config/BeanReference.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory.config;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description Bean 引用
9 | * @date 2022/3/9
10 | * /CodeDesignTutorials
11 | *
12 | */
13 | public class BeanReference {
14 |
15 | private final String beanName;
16 |
17 | public BeanReference(String beanName) {
18 | this.beanName = beanName;
19 | }
20 |
21 | public String getBeanName() {
22 | return beanName;
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/spring-step-13/src/main/java/cn/bugstack/springframework/beans/factory/config/SingletonBeanRegistry.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory.config;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description 单例 Bean 注册表
9 | * @date 2022/03/07
10 | *
11 | *
12 | */
13 | public interface SingletonBeanRegistry {
14 |
15 | /**
16 | * 返回在给定名称下注册的(原始)单例对象。
17 | * @param beanName 要查找的bean的名称
18 | * @return 返回注册的单例对象
19 | */
20 | Object getSingleton(String beanName);
21 |
22 | void registerSingleton(String beanName, Object singletonObject);
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/spring-step-13/src/main/java/cn/bugstack/springframework/context/ApplicationContextAware.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.context;
2 |
3 | import cn.bugstack.springframework.beans.BeansException;
4 | import cn.bugstack.springframework.beans.factory.Aware;
5 |
6 | /**
7 | *
8 | *
9 | *
10 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
11 | * @description 实现此接口,既能感知到所属的 ApplicationContext
12 | * @date 2022/3/11
13 | * /CodeDesignTutorials
14 | *
15 | */
16 | public interface ApplicationContextAware extends Aware {
17 |
18 | void setApplicationContext(ApplicationContext applicationContext) throws BeansException;
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/spring-step-13/src/main/java/cn/bugstack/springframework/context/annotation/Scope.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.context.annotation;
2 |
3 | import java.lang.annotation.*;
4 |
5 | @Target({ElementType.TYPE, ElementType.METHOD})
6 | @Retention(RetentionPolicy.RUNTIME)
7 | @Documented
8 | public @interface Scope {
9 |
10 | String value() default "singleton";
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/spring-step-13/src/main/java/cn/bugstack/springframework/core/io/Resource.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.core.io;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 |
6 | /**
7 | *
8 | *
9 | *
10 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
11 | * @description 资源处理接口
12 | * @date 2022/3/9
13 | *
14 | *
15 | */
16 | public interface Resource {
17 |
18 | InputStream getInputStream() throws IOException;
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/spring-step-13/src/main/java/cn/bugstack/springframework/core/io/ResourceLoader.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.core.io;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description 资源加载器
9 | * @date 2022/3/9
10 | *
11 | *
12 | */
13 | public interface ResourceLoader {
14 |
15 | /**
16 | * Pseudo URL prefix for loading from the class path: "classpath:"
17 | */
18 | String CLASSPATH_URL_PREFIX = "classpath:";
19 |
20 | Resource getResource(String location);
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/spring-step-13/src/test/java/cn/bugstack/springframework/test/bean/IUserService.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.test.bean;
2 |
3 | public interface IUserService {
4 |
5 | String queryUserInfo();
6 |
7 | String register(String userName);
8 | }
9 |
--------------------------------------------------------------------------------
/spring-step-13/src/test/resources/spring-scan.xml:
--------------------------------------------------------------------------------
1 |
2 |
Out-of-the-box implementations are available for JDK dynamic proxies 8 | * and for CGLIB proxies, as applied by DefaultAopProxyFactory 9 | * 10 | * AOP 代理的抽象 11 | * 12 | *
13 | * 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获!
14 | * 公众号:bugstack虫洞栈
15 | * Create by 小傅哥(fustack)
16 | */
17 | public interface AopProxy {
18 |
19 | Object getProxy();
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/spring-step-14/src/main/java/cn/bugstack/springframework/beans/BeansException.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description 定义 Bean 异常
9 | * @date 2022/3/7
10 | *
11 | *
12 | */
13 | public class BeansException extends RuntimeException{
14 |
15 | public BeansException(String msg) {
16 | super(msg);
17 | }
18 |
19 | public BeansException(String msg, Throwable cause) {
20 | super(msg, cause);
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/spring-step-14/src/main/java/cn/bugstack/springframework/beans/factory/Aware.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description 标记类接口,实现该接口可以被Spring容器感知
9 | * @date 2022/3/11
10 | * /CodeDesignTutorials
11 | *
12 | */
13 | public interface Aware {
14 | }
15 |
--------------------------------------------------------------------------------
/spring-step-14/src/main/java/cn/bugstack/springframework/beans/factory/BeanClassLoaderAware.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description Callback that allows a bean to be aware of the bean
9 | * {@link ClassLoader class loader}; that is, the class loader used by the
10 | * present bean factory to load bean classes.
11 | * @date 2022/3/11
12 | * /CodeDesignTutorials
13 | *
14 | */
15 | public interface BeanClassLoaderAware extends Aware {
16 |
17 | void setBeanClassLoader(ClassLoader classLoader);
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/spring-step-14/src/main/java/cn/bugstack/springframework/beans/factory/BeanFactoryAware.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | import cn.bugstack.springframework.beans.BeansException;
4 |
5 | /**
6 | *
7 | *
8 | *
9 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
10 | * @description 实现此接口,既能感知到所属的 BeanFactory
11 | * @date 2022/3/11
12 | * /CodeDesignTutorials
13 | *
14 | */
15 | public interface BeanFactoryAware extends Aware {
16 |
17 | void setBeanFactory(BeanFactory beanFactory) throws BeansException;
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/spring-step-14/src/main/java/cn/bugstack/springframework/beans/factory/HierarchicalBeanFactory.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description Sub-interface implemented by bean factories that can be part
9 | * of a hierarchy.
10 | * @date 2022/3/9
11 | * /CodeDesignTutorials
12 | *
13 | */
14 | public interface HierarchicalBeanFactory extends BeanFactory {
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/spring-step-14/src/main/java/cn/bugstack/springframework/beans/factory/InitializingBean.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description 实现此接口的 Bean 对象,会在 BeanFactory 设置属性后作出相应的处理,如:执行自定义初始化,或者仅仅检查是否设置了所有强制属性。
9 | * @date 2022/3/10
10 | * /CodeDesignTutorials
11 | *
12 | */
13 | public interface InitializingBean {
14 |
15 | /**
16 | * Bean 处理了属性填充后调用
17 | *
18 | * @throws Exception
19 | */
20 | void afterPropertiesSet() throws Exception;
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/spring-step-14/src/main/java/cn/bugstack/springframework/beans/factory/config/BeanReference.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory.config;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description Bean 引用
9 | * @date 2022/3/9
10 | * /CodeDesignTutorials
11 | *
12 | */
13 | public class BeanReference {
14 |
15 | private final String beanName;
16 |
17 | public BeanReference(String beanName) {
18 | this.beanName = beanName;
19 | }
20 |
21 | public String getBeanName() {
22 | return beanName;
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/spring-step-14/src/main/java/cn/bugstack/springframework/beans/factory/config/SingletonBeanRegistry.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory.config;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description 单例 Bean 注册表
9 | * @date 2022/03/07
10 | *
11 | *
12 | */
13 | public interface SingletonBeanRegistry {
14 |
15 | /**
16 | * 返回在给定名称下注册的(原始)单例对象。
17 | * @param beanName 要查找的bean的名称
18 | * @return 返回注册的单例对象
19 | */
20 | Object getSingleton(String beanName);
21 |
22 | void registerSingleton(String beanName, Object singletonObject);
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/spring-step-14/src/main/java/cn/bugstack/springframework/context/ApplicationContextAware.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.context;
2 |
3 | import cn.bugstack.springframework.beans.BeansException;
4 | import cn.bugstack.springframework.beans.factory.Aware;
5 |
6 | /**
7 | *
8 | *
9 | *
10 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
11 | * @description 实现此接口,既能感知到所属的 ApplicationContext
12 | * @date 2022/3/11
13 | * /CodeDesignTutorials
14 | *
15 | */
16 | public interface ApplicationContextAware extends Aware {
17 |
18 | void setApplicationContext(ApplicationContext applicationContext) throws BeansException;
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/spring-step-14/src/main/java/cn/bugstack/springframework/context/annotation/Scope.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.context.annotation;
2 |
3 | import java.lang.annotation.*;
4 |
5 | @Target({ElementType.TYPE, ElementType.METHOD})
6 | @Retention(RetentionPolicy.RUNTIME)
7 | @Documented
8 | public @interface Scope {
9 |
10 | String value() default "singleton";
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/spring-step-14/src/main/java/cn/bugstack/springframework/core/io/Resource.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.core.io;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 |
6 | /**
7 | *
8 | *
9 | *
10 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
11 | * @description 资源处理接口
12 | * @date 2022/3/9
13 | *
14 | *
15 | */
16 | public interface Resource {
17 |
18 | InputStream getInputStream() throws IOException;
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/spring-step-14/src/main/java/cn/bugstack/springframework/core/io/ResourceLoader.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.core.io;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description 资源加载器
9 | * @date 2022/3/9
10 | *
11 | *
12 | */
13 | public interface ResourceLoader {
14 |
15 | /**
16 | * Pseudo URL prefix for loading from the class path: "classpath:"
17 | */
18 | String CLASSPATH_URL_PREFIX = "classpath:";
19 |
20 | Resource getResource(String location);
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/spring-step-14/src/main/java/cn/bugstack/springframework/util/StringValueResolver.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.util;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description Simple strategy interface for resolving a String value.
9 | * Used by {@link cn.bugstack.springframework.beans.factory.config.ConfigurableBeanFactory}.
10 | * @date 2022/3/9
11 | * /CodeDesignTutorials
12 | *
13 | */
14 | public interface StringValueResolver {
15 |
16 | String resolveStringValue(String strVal);
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/spring-step-14/src/test/java/cn/bugstack/springframework/test/bean/IUserService.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.test.bean;
2 |
3 | public interface IUserService {
4 |
5 | String queryUserInfo();
6 |
7 | String register(String userName);
8 | }
9 |
--------------------------------------------------------------------------------
/spring-step-14/src/test/java/cn/bugstack/springframework/test/bean/UserDao.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.test.bean;
2 |
3 | import cn.bugstack.springframework.stereotype.Component;
4 |
5 | import java.util.HashMap;
6 | import java.util.Map;
7 |
8 | @Component
9 | public class UserDao {
10 |
11 | private static Map Out-of-the-box implementations are available for JDK dynamic proxies
8 | * and for CGLIB proxies, as applied by DefaultAopProxyFactory
9 | *
10 | * AOP 代理的抽象
11 | *
12 | *
13 | * 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获!
14 | * 公众号:bugstack虫洞栈
15 | * Create by 小傅哥(fustack)
16 | */
17 | public interface AopProxy {
18 |
19 | Object getProxy();
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/spring-step-15/src/main/java/cn/bugstack/springframework/beans/BeansException.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans;
2 |
3 | /**
4 | * 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获!
5 | * 公众号:bugstack虫洞栈
6 | * Create by 小傅哥(fustack)
7 | */
8 | public class BeansException extends RuntimeException {
9 |
10 | public BeansException(String msg) {
11 | super(msg);
12 | }
13 |
14 | public BeansException(String msg, Throwable cause) {
15 | super(msg, cause);
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/spring-step-15/src/main/java/cn/bugstack/springframework/beans/factory/BeanClassLoaderAware.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | * Callback that allows a bean to be aware of the bean
5 | * {@link ClassLoader class loader}; that is, the class loader used by the
6 | * present bean factory to load bean classes.
7 | *
8 | * 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获!
9 | * 公众号:bugstack虫洞栈
10 | * Create by 小傅哥(fustack)
11 | */
12 | public interface BeanClassLoaderAware extends Aware{
13 |
14 | void setBeanClassLoader(ClassLoader classLoader);
15 |
16 | }
17 |
18 |
19 |
--------------------------------------------------------------------------------
/spring-step-15/src/main/java/cn/bugstack/springframework/beans/factory/BeanFactory.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | import cn.bugstack.springframework.beans.BeansException;
4 |
5 | /**
6 | * 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获!
7 | * 公众号:bugstack虫洞栈
8 | * Create by 小傅哥(fustack)
9 | */
10 | public interface BeanFactory {
11 |
12 | Object getBean(String name) throws BeansException;
13 |
14 | Object getBean(String name, Object... args) throws BeansException;
15 |
16 |
8 | * 单例注册表
9 | */
10 | public interface SingletonBeanRegistry {
11 |
12 | Object getSingleton(String beanName);
13 |
14 | void registerSingleton(String beanName, Object singletonObject);
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/spring-step-15/src/main/java/cn/bugstack/springframework/context/annotation/Scope.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.context.annotation;
2 |
3 | import java.lang.annotation.*;
4 |
5 | @Target({ElementType.TYPE, ElementType.METHOD})
6 | @Retention(RetentionPolicy.RUNTIME)
7 | @Documented
8 | public @interface Scope {
9 |
10 | String value() default "singleton";
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/spring-step-15/src/main/java/cn/bugstack/springframework/core/io/Resource.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.core.io;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 |
6 | public interface Resource {
7 |
8 | InputStream getInputStream() throws IOException;
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/spring-step-15/src/main/java/cn/bugstack/springframework/core/io/ResourceLoader.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.core.io;
2 |
3 | public interface ResourceLoader {
4 |
5 | /**
6 | * Pseudo URL prefix for loading from the class path: "classpath:"
7 | */
8 | String CLASSPATH_URL_PREFIX = "classpath:";
9 |
10 | Resource getResource(String location);
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/spring-step-15/src/main/java/cn/bugstack/springframework/stereotype/Component.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.stereotype;
2 |
3 | import java.lang.annotation.*;
4 |
5 | /**
6 | * Indicates that an annotated class is a "component".
7 | * Such classes are considered as candidates for auto-detection
8 | * when using annotation-based configuration and classpath scanning.
9 | */
10 | @Target(ElementType.TYPE)
11 | @Retention(RetentionPolicy.RUNTIME)
12 | @Documented
13 | public @interface Component {
14 |
15 | String value() default "";
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/spring-step-15/src/main/java/cn/bugstack/springframework/util/StringValueResolver.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.util;
2 |
3 | /**
4 | * Simple strategy interface for resolving a String value.
5 | * Used by {@link cn.bugstack.springframework.beans.factory.config.ConfigurableBeanFactory}.
6 | *
7 | * 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获!
8 | * 公众号:bugstack虫洞栈
9 | * Create by 小傅哥(fustack)
10 | */
11 | public interface StringValueResolver {
12 |
13 | String resolveStringValue(String strVal);
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/spring-step-15/src/test/java/cn/bugstack/springframework/test/bean/IUserService.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.test.bean;
2 |
3 | public interface IUserService {
4 |
5 | String queryUserInfo();
6 |
7 | String register(String userName);
8 | }
9 |
--------------------------------------------------------------------------------
/spring-step-15/src/test/java/cn/bugstack/springframework/test/bean/UserServiceBeforeAdvice.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.test.bean;
2 |
3 | import cn.bugstack.springframework.aop.MethodBeforeAdvice;
4 |
5 | import java.lang.reflect.Method;
6 |
7 | public class UserServiceBeforeAdvice implements MethodBeforeAdvice {
8 |
9 | @Override
10 | public void before(Method method, Object[] args, Object target) throws Throwable {
11 | System.out.println("拦截方法:" + method.getName());
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/spring-step-15/src/test/resources/token.properties:
--------------------------------------------------------------------------------
1 | token=RejDlI78hu223Opo983Ds
--------------------------------------------------------------------------------
/spring-step-15/target/test-classes/META-INF/spring-step-15.kotlin_module:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/spring-step-15/target/test-classes/token.properties:
--------------------------------------------------------------------------------
1 | token=RejDlI78hu223Opo983Ds
--------------------------------------------------------------------------------
/spring-step-16/src/main/java/cn/bugstack/springframework/aop/BeforeAdvice.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.aop;
2 |
3 | import org.aopalliance.aop.Advice;
4 |
5 | /**
6 | *
7 | *
8 | *
9 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
10 | * @description Common marker interface for before advice, such as {@link MethodBeforeAdvice}.
11 | * @date 2022/3/14
12 | * /CodeDesignTutorials
13 | *
14 | */
15 | public interface BeforeAdvice extends Advice {
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/spring-step-16/src/main/java/cn/bugstack/springframework/aop/ClassFilter.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.aop;
2 |
3 | /**
4 | * Filter that restricts matching of a pointcut or introduction to
5 | * a given set of target classes.
6 | *
7 | * 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获!
8 | * 公众号:bugstack虫洞栈
9 | * Create by 小傅哥(fustack)
10 | */
11 | public interface ClassFilter {
12 |
13 | /**
14 | * Should the pointcut apply to the given interface or target class?
15 | * @param clazz the candidate target class
16 | * @return whether the advice should apply to the given target class
17 | */
18 | boolean matches(Class> clazz);
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/spring-step-16/src/main/java/cn/bugstack/springframework/aop/MethodMatcher.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.aop;
2 |
3 | import java.lang.reflect.Method;
4 |
5 | /**
6 | * Part of a {@link Pointcut}: Checks whether the target method is eligible for advice.
7 | *
8 | * 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获!
9 | * 公众号:bugstack虫洞栈
10 | * Create by 小傅哥(fustack)
11 | */
12 | public interface MethodMatcher {
13 |
14 | /**
15 | * Perform static checking whether the given method matches. If this
16 | * @return whether or not this method matches statically
17 | */
18 | boolean matches(Method method, Class> targetClass);
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/spring-step-16/src/main/java/cn/bugstack/springframework/aop/PointcutAdvisor.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.aop;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description Superinterface for all Advisors that are driven by a pointcut.
9 | * This covers nearly all advisors except introduction advisors,
10 | * for which method-level matching doesn't apply.
11 | * @date 2022/3/14
12 | * /CodeDesignTutorials
13 | *
14 | */
15 | public interface PointcutAdvisor extends Advisor {
16 |
17 | /**
18 | * Get the Pointcut that drives this advisor.
19 | */
20 | Pointcut getPointcut();
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/spring-step-16/src/main/java/cn/bugstack/springframework/aop/framework/AopProxy.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.aop.framework;
2 |
3 | /**
4 | * Delegate interface for a configured AOP proxy, allowing for the creation
5 | * of actual proxy objects.
6 | *
7 | * Out-of-the-box implementations are available for JDK dynamic proxies
8 | * and for CGLIB proxies, as applied by DefaultAopProxyFactory
9 | *
10 | * AOP 代理的抽象
11 | *
12 | *
13 | * 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获!
14 | * 公众号:bugstack虫洞栈
15 | * Create by 小傅哥(fustack)
16 | */
17 | public interface AopProxy {
18 |
19 | Object getProxy();
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/spring-step-16/src/main/java/cn/bugstack/springframework/beans/BeansException.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description 定义 Bean 异常
9 | * @date 2022/3/7
10 | *
11 | *
12 | */
13 | public class BeansException extends RuntimeException{
14 |
15 | public BeansException(String msg) {
16 | super(msg);
17 | }
18 |
19 | public BeansException(String msg, Throwable cause) {
20 | super(msg, cause);
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/spring-step-16/src/main/java/cn/bugstack/springframework/beans/factory/Aware.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description 标记类接口,实现该接口可以被Spring容器感知
9 | * @date 2022/3/11
10 | * /CodeDesignTutorials
11 | *
12 | */
13 | public interface Aware {
14 | }
15 |
--------------------------------------------------------------------------------
/spring-step-16/src/main/java/cn/bugstack/springframework/beans/factory/BeanClassLoaderAware.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description Callback that allows a bean to be aware of the bean
9 | * {@link ClassLoader class loader}; that is, the class loader used by the
10 | * present bean factory to load bean classes.
11 | * @date 2022/3/11
12 | * /CodeDesignTutorials
13 | *
14 | */
15 | public interface BeanClassLoaderAware extends Aware {
16 |
17 | void setBeanClassLoader(ClassLoader classLoader);
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/spring-step-16/src/main/java/cn/bugstack/springframework/beans/factory/BeanFactoryAware.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | import cn.bugstack.springframework.beans.BeansException;
4 |
5 | /**
6 | *
7 | *
8 | *
9 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
10 | * @description 实现此接口,既能感知到所属的 BeanFactory
11 | * @date 2022/3/11
12 | * /CodeDesignTutorials
13 | *
14 | */
15 | public interface BeanFactoryAware extends Aware {
16 |
17 | void setBeanFactory(BeanFactory beanFactory) throws BeansException;
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/spring-step-16/src/main/java/cn/bugstack/springframework/beans/factory/HierarchicalBeanFactory.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description Sub-interface implemented by bean factories that can be part
9 | * of a hierarchy.
10 | * @date 2022/3/9
11 | * /CodeDesignTutorials
12 | *
13 | */
14 | public interface HierarchicalBeanFactory extends BeanFactory {
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/spring-step-16/src/main/java/cn/bugstack/springframework/beans/factory/InitializingBean.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description 实现此接口的 Bean 对象,会在 BeanFactory 设置属性后作出相应的处理,如:执行自定义初始化,或者仅仅检查是否设置了所有强制属性。
9 | * @date 2022/3/10
10 | * /CodeDesignTutorials
11 | *
12 | */
13 | public interface InitializingBean {
14 |
15 | /**
16 | * Bean 处理了属性填充后调用
17 | *
18 | * @throws Exception
19 | */
20 | void afterPropertiesSet() throws Exception;
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/spring-step-16/src/main/java/cn/bugstack/springframework/beans/factory/ObjectFactory.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | import cn.bugstack.springframework.beans.BeansException;
4 |
5 | /**
6 | *
7 | *
8 | *
9 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
10 | * @description Defines a factory which can return an Object instance (possibly shared or independent) when invoked.
11 | * @date 2022/3/16
12 | * /CodeDesignTutorials
13 | *
14 | */
15 | public interface ObjectFactory Out-of-the-box implementations are available for JDK dynamic proxies
8 | * and for CGLIB proxies, as applied by DefaultAopProxyFactory
9 | *
10 | * AOP 代理的抽象
11 | *
12 | *
13 | * 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获!
14 | * 公众号:bugstack虫洞栈
15 | * Create by 小傅哥(fustack)
16 | */
17 | public interface AopProxy {
18 |
19 | Object getProxy();
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/spring-step-17/src/main/java/cn/bugstack/springframework/beans/BeansException.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description 定义 Bean 异常
9 | * @date 2022/3/7
10 | *
11 | *
12 | */
13 | public class BeansException extends RuntimeException{
14 |
15 | public BeansException(String msg) {
16 | super(msg);
17 | }
18 |
19 | public BeansException(String msg, Throwable cause) {
20 | super(msg, cause);
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/spring-step-17/src/main/java/cn/bugstack/springframework/beans/factory/Aware.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description 标记类接口,实现该接口可以被Spring容器感知
9 | * @date 2022/3/11
10 | * /CodeDesignTutorials
11 | *
12 | */
13 | public interface Aware {
14 | }
15 |
--------------------------------------------------------------------------------
/spring-step-17/src/main/java/cn/bugstack/springframework/beans/factory/BeanClassLoaderAware.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description Callback that allows a bean to be aware of the bean
9 | * {@link ClassLoader class loader}; that is, the class loader used by the
10 | * present bean factory to load bean classes.
11 | * @date 2022/3/11
12 | * /CodeDesignTutorials
13 | *
14 | */
15 | public interface BeanClassLoaderAware extends Aware {
16 |
17 | void setBeanClassLoader(ClassLoader classLoader);
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/spring-step-17/src/main/java/cn/bugstack/springframework/beans/factory/BeanFactoryAware.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | import cn.bugstack.springframework.beans.BeansException;
4 |
5 | /**
6 | *
7 | *
8 | *
9 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
10 | * @description 实现此接口,既能感知到所属的 BeanFactory
11 | * @date 2022/3/11
12 | * /CodeDesignTutorials
13 | *
14 | */
15 | public interface BeanFactoryAware extends Aware {
16 |
17 | void setBeanFactory(BeanFactory beanFactory) throws BeansException;
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/spring-step-17/src/main/java/cn/bugstack/springframework/beans/factory/HierarchicalBeanFactory.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description Sub-interface implemented by bean factories that can be part
9 | * of a hierarchy.
10 | * @date 2022/3/9
11 | * /CodeDesignTutorials
12 | *
13 | */
14 | public interface HierarchicalBeanFactory extends BeanFactory {
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/spring-step-17/src/main/java/cn/bugstack/springframework/beans/factory/InitializingBean.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description 实现此接口的 Bean 对象,会在 BeanFactory 设置属性后作出相应的处理,如:执行自定义初始化,或者仅仅检查是否设置了所有强制属性。
9 | * @date 2022/3/10
10 | * /CodeDesignTutorials
11 | *
12 | */
13 | public interface InitializingBean {
14 |
15 | /**
16 | * Bean 处理了属性填充后调用
17 | *
18 | * @throws Exception
19 | */
20 | void afterPropertiesSet() throws Exception;
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/spring-step-17/src/main/java/cn/bugstack/springframework/beans/factory/ObjectFactory.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | import cn.bugstack.springframework.beans.BeansException;
4 |
5 | /**
6 | *
7 | *
8 | *
9 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
10 | * @description Defines a factory which can return an Object instance (possibly shared or independent) when invoked.
11 | * @date 2022/3/16
12 | * /CodeDesignTutorials
13 | *
14 | */
15 | public interface ObjectFactory Out-of-the-box implementations are available for JDK dynamic proxies
8 | * and for CGLIB proxies, as applied by DefaultAopProxyFactory
9 | *
10 | * AOP 代理的抽象
11 | *
12 | *
13 | * 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获!
14 | * 公众号:bugstack虫洞栈
15 | * Create by 小傅哥(fustack)
16 | */
17 | public interface AopProxy {
18 |
19 | Object getProxy();
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/spring-step-18/src/main/java/cn/bugstack/springframework/beans/BeansException.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans;
2 |
3 | /**
4 | *
5 | * @description 定义 Bean 异常
6 | * @date 2022/3/7
7 | *
8 | *
9 | */
10 | public class BeansException extends RuntimeException{
11 |
12 | public BeansException(String msg) {
13 | super(msg);
14 | }
15 |
16 | public BeansException(String msg, Throwable cause) {
17 | super(msg, cause);
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/spring-step-18/src/main/java/cn/bugstack/springframework/beans/factory/Aware.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | * @description 标记类接口,实现该接口可以被Spring容器感知
6 | * @date 2022/3/11
7 | * /CodeDesignTutorials
8 | *
9 | */
10 | public interface Aware {
11 | }
12 |
--------------------------------------------------------------------------------
/spring-step-18/src/main/java/cn/bugstack/springframework/beans/factory/BeanClassLoaderAware.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | * @description Callback that allows a bean to be aware of the bean
6 | * {@link ClassLoader class loader}; that is, the class loader used by the
7 | * present bean factory to load bean classes.
8 | * @date 2022/3/11
9 | * /CodeDesignTutorials
10 | *
11 | */
12 | public interface BeanClassLoaderAware extends Aware {
13 |
14 | void setBeanClassLoader(ClassLoader classLoader);
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/spring-step-18/src/main/java/cn/bugstack/springframework/beans/factory/BeanFactoryAware.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | import cn.bugstack.springframework.beans.BeansException;
4 |
5 | /**
6 | *
7 | * @description 实现此接口,既能感知到所属的 BeanFactory
8 | * @date 2022/3/11
9 | * /CodeDesignTutorials
10 | *
11 | */
12 | public interface BeanFactoryAware extends Aware {
13 |
14 | void setBeanFactory(BeanFactory beanFactory) throws BeansException;
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/spring-step-18/src/main/java/cn/bugstack/springframework/beans/factory/BeanNameAware.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | * @description Interface to be implemented by beans that want to be aware of their
6 | * bean name in a bean factory. Note that it is not usually recommended
7 | * that an object depend on its bean name, as this represents a potentially
8 | * brittle dependence on external configuration, as well as a possibly
9 | * unnecessary dependence on a Spring API.
10 | * @date 2022/3/11
11 | * /CodeDesignTutorials
12 | *
13 | */
14 | public interface BeanNameAware {
15 |
16 | void setBeanName(String name);
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/spring-step-18/src/main/java/cn/bugstack/springframework/beans/factory/DisposableBean.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | * @description Interface to be implemented by beans that want to release resources
6 | * on destruction. A BeanFactory is supposed to invoke the destroy
7 | * method if it disposes a cached singleton. An application context
8 | * is supposed to dispose all of its singletons on close.
9 | * @date 2022/3/10
10 | * /CodeDesignTutorials
11 | *
12 | */
13 | public interface DisposableBean {
14 |
15 | void destroy() throws Exception;
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/spring-step-18/src/main/java/cn/bugstack/springframework/beans/factory/FactoryBean.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | * @description Interface to be implemented by objects used within a {@link BeanFactory}
6 | * which are themselves factories. If a bean implements this interface,
7 | * it is used as a factory for an object to expose, not directly as a bean
8 | * instance that will be exposed itself.
9 | * @date 2022/3/11
10 | * /CodeDesignTutorials
11 | *
12 | */
13 | public interface FactoryBean Out-of-the-box implementations are available for JDK dynamic proxies
8 | * and for CGLIB proxies, as applied by DefaultAopProxyFactory
9 | *
10 | * AOP 代理的抽象
11 | *
12 | *
13 | * 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获!
14 | * 公众号:bugstack虫洞栈
15 | * Create by 小傅哥(fustack)
16 | */
17 | public interface AopProxy {
18 |
19 | Object getProxy();
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/spring-step-19/src/main/java/cn/bugstack/springframework/beans/BeansException.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans;
2 |
3 | /**
4 | *
5 | * @description 定义 Bean 异常
6 | * @date 2022/3/7
7 | *
8 | *
9 | */
10 | public class BeansException extends RuntimeException{
11 |
12 | public BeansException(String msg) {
13 | super(msg);
14 | }
15 |
16 | public BeansException(String msg, Throwable cause) {
17 | super(msg, cause);
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/spring-step-19/src/main/java/cn/bugstack/springframework/beans/factory/Aware.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | * @description 标记类接口,实现该接口可以被Spring容器感知
6 | * @date 2022/3/11
7 | * /CodeDesignTutorials
8 | *
9 | */
10 | public interface Aware {
11 | }
12 |
--------------------------------------------------------------------------------
/spring-step-19/src/main/java/cn/bugstack/springframework/beans/factory/BeanClassLoaderAware.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | * @description Callback that allows a bean to be aware of the bean
6 | * {@link ClassLoader class loader}; that is, the class loader used by the
7 | * present bean factory to load bean classes.
8 | * @date 2022/3/11
9 | * /CodeDesignTutorials
10 | *
11 | */
12 | public interface BeanClassLoaderAware extends Aware {
13 |
14 | void setBeanClassLoader(ClassLoader classLoader);
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/spring-step-19/src/main/java/cn/bugstack/springframework/beans/factory/BeanFactoryAware.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | import cn.bugstack.springframework.beans.BeansException;
4 |
5 | /**
6 | *
7 | * @description 实现此接口,既能感知到所属的 BeanFactory
8 | * @date 2022/3/11
9 | * /CodeDesignTutorials
10 | *
11 | */
12 | public interface BeanFactoryAware extends Aware {
13 |
14 | void setBeanFactory(BeanFactory beanFactory) throws BeansException;
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/spring-step-19/src/main/java/cn/bugstack/springframework/beans/factory/BeanNameAware.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | * @description Interface to be implemented by beans that want to be aware of their
6 | * bean name in a bean factory. Note that it is not usually recommended
7 | * that an object depend on its bean name, as this represents a potentially
8 | * brittle dependence on external configuration, as well as a possibly
9 | * unnecessary dependence on a Spring API.
10 | * @date 2022/3/11
11 | * /CodeDesignTutorials
12 | *
13 | */
14 | public interface BeanNameAware {
15 |
16 | void setBeanName(String name);
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/spring-step-19/src/main/java/cn/bugstack/springframework/beans/factory/DisposableBean.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | * @description Interface to be implemented by beans that want to release resources
6 | * on destruction. A BeanFactory is supposed to invoke the destroy
7 | * method if it disposes a cached singleton. An application context
8 | * is supposed to dispose all of its singletons on close.
9 | * @date 2022/3/10
10 | * /CodeDesignTutorials
11 | *
12 | */
13 | public interface DisposableBean {
14 |
15 | void destroy() throws Exception;
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/spring-step-19/src/main/java/cn/bugstack/springframework/beans/factory/FactoryBean.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | * @description Interface to be implemented by objects used within a {@link BeanFactory}
6 | * which are themselves factories. If a bean implements this interface,
7 | * it is used as a factory for an object to expose, not directly as a bean
8 | * instance that will be exposed itself.
9 | * @date 2022/3/11
10 | * /CodeDesignTutorials
11 | *
12 | */
13 | public interface FactoryBean Out-of-the-box implementations are available for JDK dynamic proxies
8 | * and for CGLIB proxies, as applied by DefaultAopProxyFactory
9 | *
10 | * AOP 代理的抽象
11 | *
12 | *
13 | * 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获!
14 | * 公众号:bugstack虫洞栈
15 | * Create by 小傅哥(fustack)
16 | */
17 | public interface AopProxy {
18 |
19 | Object getProxy();
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/spring-step-21/src/main/java/cn/bugstack/springframework/beans/BeansException.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans;
2 |
3 | /**
4 | *
5 | * @description 定义 Bean 异常
6 | * @date 2022/3/7
7 | *
8 | *
9 | */
10 | public class BeansException extends RuntimeException{
11 |
12 | public BeansException(String msg) {
13 | super(msg);
14 | }
15 |
16 | public BeansException(String msg, Throwable cause) {
17 | super(msg, cause);
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/spring-step-21/src/main/java/cn/bugstack/springframework/beans/factory/Aware.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | * @description 标记类接口,实现该接口可以被Spring容器感知
6 | * @date 2022/3/11
7 | * /CodeDesignTutorials
8 | *
9 | */
10 | public interface Aware {
11 | }
12 |
--------------------------------------------------------------------------------
/spring-step-21/src/main/java/cn/bugstack/springframework/beans/factory/BeanClassLoaderAware.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | * @description Callback that allows a bean to be aware of the bean
6 | * {@link ClassLoader class loader}; that is, the class loader used by the
7 | * present bean factory to load bean classes.
8 | * @date 2022/3/11
9 | * /CodeDesignTutorials
10 | *
11 | */
12 | public interface BeanClassLoaderAware extends Aware {
13 |
14 | void setBeanClassLoader(ClassLoader classLoader);
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/spring-step-21/src/main/java/cn/bugstack/springframework/beans/factory/BeanFactoryAware.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | import cn.bugstack.springframework.beans.BeansException;
4 |
5 | /**
6 | *
7 | * @description 实现此接口,既能感知到所属的 BeanFactory
8 | * @date 2022/3/11
9 | * /CodeDesignTutorials
10 | *
11 | */
12 | public interface BeanFactoryAware extends Aware {
13 |
14 | void setBeanFactory(BeanFactory beanFactory) throws BeansException;
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/spring-step-21/src/main/java/cn/bugstack/springframework/beans/factory/BeanNameAware.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | * @description Interface to be implemented by beans that want to be aware of their
6 | * bean name in a bean factory. Note that it is not usually recommended
7 | * that an object depend on its bean name, as this represents a potentially
8 | * brittle dependence on external configuration, as well as a possibly
9 | * unnecessary dependence on a Spring API.
10 | * @date 2022/3/11
11 | * /CodeDesignTutorials
12 | *
13 | */
14 | public interface BeanNameAware {
15 |
16 | void setBeanName(String name);
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/spring-step-21/src/main/java/cn/bugstack/springframework/beans/factory/DisposableBean.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | * @description Interface to be implemented by beans that want to release resources
6 | * on destruction. A BeanFactory is supposed to invoke the destroy
7 | * method if it disposes a cached singleton. An application context
8 | * is supposed to dispose all of its singletons on close.
9 | * @date 2022/3/10
10 | * /CodeDesignTutorials
11 | *
12 | */
13 | public interface DisposableBean {
14 |
15 | void destroy() throws Exception;
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/spring-step-21/src/main/java/cn/bugstack/springframework/beans/factory/FactoryBean.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.beans.factory;
2 |
3 | /**
4 | *
5 | * @description Interface to be implemented by objects used within a {@link BeanFactory}
6 | * which are themselves factories. If a bean implements this interface,
7 | * it is used as a factory for an object to expose, not directly as a bean
8 | * instance that will be exposed itself.
9 | * @date 2022/3/11
10 | * /CodeDesignTutorials
11 | *
12 | */
13 | public interface FactoryBean {
14 |
15 | /** Convert the source object of type {@code S} to target type {@code T}. */
16 | T convert(S source);
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/spring-step-17/src/main/java/cn/bugstack/springframework/core/io/Resource.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.core.io;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 |
6 | /**
7 | *
8 | *
9 | *
10 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
11 | * @description 资源处理接口
12 | * @date 2022/3/9
13 | *
14 | *
15 | */
16 | public interface Resource {
17 |
18 | InputStream getInputStream() throws IOException;
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/spring-step-17/src/main/java/cn/bugstack/springframework/core/io/ResourceLoader.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.core.io;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description 资源加载器
9 | * @date 2022/3/9
10 | *
11 | *
12 | */
13 | public interface ResourceLoader {
14 |
15 | /**
16 | * Pseudo URL prefix for loading from the class path: "classpath:"
17 | */
18 | String CLASSPATH_URL_PREFIX = "classpath:";
19 |
20 | Resource getResource(String location);
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/spring-step-17/src/main/java/cn/bugstack/springframework/util/StringValueResolver.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.util;
2 |
3 | /**
4 | *
5 | *
6 | *
7 | * 作者:DerekYRC https://github.com/DerekYRC/mini-spring
8 | * @description Simple strategy interface for resolving a String value.
9 | * Used by {@link cn.bugstack.springframework.beans.factory.config.ConfigurableBeanFactory}.
10 | * @date 2022/3/9
11 | * /CodeDesignTutorials
12 | *
13 | */
14 | public interface StringValueResolver {
15 |
16 | String resolveStringValue(String strVal);
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/spring-step-17/src/test/java/cn/bugstack/springframework/test/converter/StringToIntegerConverter.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.test.converter;
2 |
3 | import cn.bugstack.springframework.core.convert.converter.Converter;
4 |
5 | /**
6 | * 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获!
7 | * 公众号:bugstack虫洞栈
8 | * Create by 小傅哥(fustack)
9 | */
10 | public class StringToIntegerConverter implements Converter {
11 |
12 | /** Convert the source object of type {@code S} to target type {@code T}. */
13 | T convert(S source);
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/spring-step-18/src/main/java/cn/bugstack/springframework/core/convert/converter/ConverterFactory.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.core.convert.converter;
2 |
3 | /**
4 | *
5 | * @description 类型转换工厂
6 | * @date 2022/3/16
7 | *
8 | *
9 | */
10 | public interface ConverterFactory{
11 |
12 | /**
13 | * Get the converter to convert from S to target type T, where T is also an instance of R.
14 | * @param getConverter(Class {
11 |
12 | /** Convert the source object of type {@code S} to target type {@code T}. */
13 | T convert(S source);
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/spring-step-19/src/main/java/cn/bugstack/springframework/core/convert/converter/ConverterFactory.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.core.convert.converter;
2 |
3 | /**
4 | *
5 | * @description 类型转换工厂
6 | * @date 2022/3/16
7 | *
8 | *
9 | */
10 | public interface ConverterFactory{
11 |
12 | /**
13 | * Get the converter to convert from S to target type T, where T is also an instance of R.
14 | * @param getConverter(Class {
11 |
12 | /** Convert the source object of type {@code S} to target type {@code T}. */
13 | T convert(S source);
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/spring-step-21/src/main/java/cn/bugstack/springframework/core/convert/converter/ConverterFactory.java:
--------------------------------------------------------------------------------
1 | package cn.bugstack.springframework.core.convert.converter;
2 |
3 | /**
4 | *
5 | * @description 类型转换工厂
6 | * @date 2022/3/16
7 | *
8 | *
9 | */
10 | public interface ConverterFactory{
11 |
12 | /**
13 | * Get the converter to convert from S to target type T, where T is also an instance of R.
14 | * @param getConverter(Class