Annotation的代码实现我们还是沿用Mini版本的,保持不变,复制过来便可。
package com.tom.spring.formework.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* 业务逻辑,注入接口
*/
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface GPService {
String value() default "";
}
@GPAutowired代码如下:
package com.tom.spring.formework.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* 自动注入
*/
@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface GPAutowired {
String value() default "";
}
@GPController代码如下:
package com.tom.spring.formework.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* 页面交互
*/
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface GPController {
String value() default "";
}
@GPRequestMapping代码如下:
package com.tom.spring.formework.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* 请求URL
*/
@Target({ElementType.METHOD,ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface GPRequestMapping {
String value() default "";
}
关于顶层接口设计,通过前面的学习我们了解了FactoryBean的基本作用,在此不做过多解释。
package com.tom.spring.formework.core;
public interface GPFactoryBean {
}
作为所有IoC容器的顶层设计,前面也已经详细介绍了BeanFactory的作用。
package com.tom.spring.formework.core;
/**
* 单例工厂的顶层设计
*/
public interface GPBeanFactory {
/**
* 根据beanName从IoC容器中获得一个实例Bean
* @param beanName
* @return
*/
Object getBean(String beanName) throws Exception;
public Object getBean(Class<?> beanClass) throws Exception;
}
BeanDefinition主要用于保存Bean相关的配置信息。
package com.tom.spring.formework.beans.config;
//用来存储配置文件中的信息
//相当于保存在内存中的配置
public class GPBeanDefinition {
private String beanClassName; //原生Bean的全类名
private boolean lazyInit = false; //标记是否延时加载
private String factoryBeanName; //保存beanName,在IoC容器中存储的key
public String getBeanClassName() {
return beanClassName;
}
public void setBeanClassName(String beanClassName) {
this.beanClassName = beanClassName;
}
public boolean isLazyInit() {
return lazyInit;
}
public void setLazyInit(boolean lazyInit) {
this.lazyInit = lazyInit;
}
public String getFactoryBeanName() {
return factoryBeanName;
}
public void setFactoryBeanName(String factoryBeanName) {
this.factoryBeanName = factoryBeanName;
}
}
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。