All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.blade.loader.ClassPathControllerLoader Maven / Gradle / Ivy

There is a newer version: 1.7.2-beta
Show newest version
package com.blade.loader;

import com.blade.Aop;
import com.blade.Blade;
import com.blade.ioc.Container;
import com.blade.ioc.Scope;
import com.blade.route.RouteException;

/**
 * 
 * 

* ClassPath控制器加载器 *

* * @author biezhi * @since 1.0 */ public class ClassPathControllerLoader implements ControllerLoader { private String basePackage; private ClassLoader classLoader = ClassPathControllerLoader.class.getClassLoader(); private Container container = Blade.me().container(); public ClassPathControllerLoader() { this(""); } public ClassPathControllerLoader(String basePackage) { this.basePackage = basePackage; if (this.basePackage != null && !"".equals(this.basePackage)) { if (!this.basePackage.endsWith(".")) { this.basePackage += "."; } } } @Override public Object load(String controllerName) throws RouteException { String className = basePackage + controllerName; try { // 加载控制器实例 Class controllerClass = classLoader.loadClass(className); Object controller = container.getBean(controllerClass, Scope.SINGLE); if(null == controller){ controller = Aop.create(controllerClass); container.registerBean(controller); } return controller; } catch (Exception e) { throw new RouteException(e); } } public String getBasePackage() { return basePackage; } public void setBasePackage(String basePackage) { this.basePackage = basePackage; } public ClassLoader getClassLoader() { return classLoader; } public void setClassLoader(ClassLoader classLoader) { this.classLoader = classLoader; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy