Search in sources :

Example 1 with ClassPathRouteLoader

use of com.blade.mvc.route.loader.ClassPathRouteLoader in project blade by biezhi.

the class Blade method routeConf.

/**
     * Registration of a configuration file, e.g: "com.xxx.route","route.conf"
     *
     * @param basePackage controller package name
     * @param conf        Configuration file path, the configuration file must be in
     *                    classpath
     * @return return blade
     */
public Blade routeConf(String basePackage, String conf) {
    try {
        Assert.notBlank(basePackage);
        Assert.notBlank(conf);
        InputStream ins = Blade.class.getResourceAsStream("/" + conf);
        ClassPathRouteLoader routesLoader = new ClassPathRouteLoader(ins);
        routesLoader.setBasePackage(basePackage);
        List<Route> routes = routesLoader.load();
        routers.addRoutes(routes);
    } catch (RouteException | ParseException e) {
        throw new BladeException(e);
    }
    return this;
}
Also used : RouteException(com.blade.exception.RouteException) BladeException(com.blade.exception.BladeException) InputStream(java.io.InputStream) ClassPathRouteLoader(com.blade.mvc.route.loader.ClassPathRouteLoader) ParseException(java.text.ParseException)

Aggregations

BladeException (com.blade.exception.BladeException)1 RouteException (com.blade.exception.RouteException)1 ClassPathRouteLoader (com.blade.mvc.route.loader.ClassPathRouteLoader)1 InputStream (java.io.InputStream)1 ParseException (java.text.ParseException)1