Today Context 轻量级依赖注入框架开源项目

我要开发同款
匿名用户2019年11月25日
31阅读
开发技术Java
所属分类Web应用开发、Web框架
授权协议GPL

作品详情

TODAYContext是一个轻量级依赖注入框架。

使用说明标识一个Bean使用@Component任意注解只要注解上有@Component注解就会标识为一个Bean不论多少层@Target({ElementType.TYPE,ElementType.METHOD})public@interfaceComponent{/**@returnbeanname*/String[]value()default{};/**@returnbean'sscope*/Scopescope()defaultScope.SINGLETON;String[]initMethods()default{};String[]destroyMethods()default{};}

@Singleton

@Component(scope=Scope.SINGLETON)@Target({ElementType.TYPE,ElementType.METHOD})public@interfaceSingleton{//beannameString[]value()default{};String[]initMethods()default{};String[]destroyMethods()default{};}

@Prototype

@Retention(RetentionPolicy.RUNTIME)@Component(scope=Scope.PROTOTYPE)@Target({ElementType.TYPE,ElementType.METHOD})public@interfacePrototype{//beannameString[]value()default{};String[]initMethods()default{};String[]destroyMethods()default{};}

@Configuration

@Target(ElementType.TYPE)@Component(scope=Scope.SINGLETON)public@interfaceConfiguration{}

@Service

@Component(scope=Scope.SINGLETON)@Target({ElementType.TYPE,ElementType.METHOD})public@interfaceService{String[]value()default{};//beannames}注入Bean使用@Autowired注入使用@Resource注入使用@Inject注入可自定义注解和实现PropertyValueResolver:@FunctionalInterfacepublicinterfacePropertyValueResolver{defaultbooleansupports(Fieldfield){returnfalse;}PropertyValueresolveProperty(Fieldfield)throwsContextException;}注入示例:@Controller@SuppressWarnings("serial")publicclassLoginControllerimplementsConstant,ServletContextAware{privateStringcontextPath;@AutowiredprivateUserServiceuserService;//@Inject@ResourceprivateBloggerServicebloggerService;@GET("/login")publicStringlogin(@CookieStringemail,Stringforward,Modelmodel){model.attribute(KEY_EMAIL,email);model.attribute("forward",forward);return"/login/index";}@POST("/login")@Logger(value="登录",//content="email:[${email}]"//+"passwd:[${passwd}]"//+"inputcode:[${randCode}]"//+"insession:[${randCodeInSession}]"//+"forwardto:[${forward}]"//+"msg:[${redirectModel.attribute('msg')}]"//)publicStringlogin(HttpSessionsession,@Cookie(KEY_EMAIL)StringemailInCookie,@RequestParam(required=true)Stringemail,@RequestParam(required=true)Stringpasswd,@RequestParam(required=true)StringrandCode,@RequestParam(required=false)Stringforward,@Session(RAND_CODE)StringrandCodeInSession,RedirectModelredirectModel)//{session.removeAttribute(RAND_CODE);if(!randCode.equalsIgnoreCase(randCodeInSession)){redirectModel.attribute(KEY_MSG,"验证码错误!");redirectModel.attribute(KEY_EMAIL,email);redirectModel.attribute(KEY_FORWARD,forward);returnredirectLogin(forward);}UserloginUser=userService.login(newUser().setEmail(email));if(loginUser==null){redirectModel.attribute(KEY_EMAIL,email);redirectModel.attribute(KEY_FORWARD,forward);redirectModel.attribute(KEY_MSG,email+"账号不存在!");returnredirectLogin(forward);}//
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论