Spring Boot & Cloud , lightweight framework Solon 1.4.8 released

olon is a lightweight Java base development framework . Emphasis , restraint + simplicity + open principles ; strive for , smaller , faster , more free experience . Support : RPC, REST API, MVC, Job, Micro service, WebSocket, Socket and many other development models .

Solon Cloud is a series of interface standards and configuration specifications, which is considered Solon’s distributed development kit solution.

The so-called smaller.

Kernel 0.1m, the smallest interface development unit 0.2m (compared to Dubbo, Springboot dependency packages, so small that you can almost ignore)

So-called faster.

native http helloworld test, Qps up to 120,000 as much. See: “helloworld_wrk_test

So-called more freedom: (freedom of code manipulation)

// In addition to annotation mode, manual on-demand

// Manually get configuration (Props for Properties enhancement)
Props db = Solon.cfg().getProp("db");

//Manually get the bean in the container
UserService userService = Aop.get(UserService.class);

//Manually listen to http post requests
Solon.global().post("/user/update", x-> userService.updateById(x.paramMap()));

// Manually add an RPC service
Solon.global().add("/rpc/", HelloService.class, true);

//Manually get a RPC service consumer
HelloService helloService = Nami.builder().create(HelloService.class);

//Manually add components to the container
Aop.wrapAndPut(DemoService.class);

Translated with www.DeepL.com/Translator (free version)

1. Main changes in this release

1.1 Add the sa-token-solon-plugin plugin to adapt to the sa-token authentication framework

Sample applications

@Controller
@Mapping("/test/")
public class TestController {
    @SaCheckLogin					
    @SaCheckRole("super-admin")		
    @SaCheckPermission("user-add")	
    @Mapping("atCheck")
    public AjaxJson atCheck() {
        System.out.println("This method can only be accessed by annotating the forensic rights");
        return AjaxJson.getSuccess();
    }
	
    @Mapping("atJurOr")
    @SaCheckPermission(value = {"user-add", "user-all", "user-delete"}, mode = SaMode.OR)	
    public AjaxJson atJurOr() {
        return AjaxJson.getSuccessData("user info");
    }
}

1.2 Add solon.extend.auth plug-in, Solon’s self-extending authentication framework

Sample Adaptation

@Configuration
public class Config {
    @Bean
     public AuthAdapter init() {
        return new AuthAdapter()
            .loginUrl("/login")
            .authPathMatchers(new AuthPathMatchersImpl())
            .authInterceptor(new AuthInterceptorImpl())
            .authProcessor(new AuthProcessorImpl())
            .authOnFailure((ctx, rst) -> {
                ctx.render(Result.failure(403,"No permission:("));
            });
    }
}

Sample applications

@Controller
@Mapping("/test/")
public class TestController {
    @Mapping("/hello/")
    public String hello() {
        return "hello world!";
    }
    
    @AuthRoles("admin")
    @Mapping("/admin/")
    public String admin() {
        return "hello admin!";
    }
}

1.3 Add solon-enjoy-web rapid development kit (supports enjob + activerecord experience)

Fans of the jFinal family of technologies can now have a different toy. solon-enjoy-web, which supports solon’s full transactional and caching capabilities

// Configuring the default data source
@Configuration
public class Config {
    @Bean
    public DataSource db1(@Inject("${test.db1}") HikariDataSource dataSource) {
        return dataSource;
    }
}

// Application List
@Mapping("/demo/")
@Controller
public class DemoController {
    @Mapping("")
    public Object test(){
        return Db.template("appx_get").findFirst();
    }

    @Cache(tags = "test2")
    @Mapping("/test2")
    public Object test2(){
        AppxModel dao = new AppxModel().dao();

        return dao.findById(4);
    }
}

1.4 Add the ability to convert exception subscriptions to normal output

@Component
public class GlobalException implements EventListener<Throwable> {
    @Override
    public void onEvent(Throwable e) {
        Context c = Context.current();

        if (c != null) {
            AjaxJson aj = null;
            if (e instanceof SaTokenException) {    
                NotLoginException ee = (NotLoginException) e;
                aj = AjaxJson.getNotLogin().setMsg(ee.getMessage());
            } else if (e instanceof NotRoleException) {     
                NotRoleException ee = (NotRoleException) e;
                aj = AjaxJson.getNotJur("No such role:" + ee.getRole());
            } else if (e instanceof NotPermissionException) {  
                NotPermissionException ee = (NotPermissionException) e;
                aj = AjaxJson.getNotJur("No such permission:" + ee.getCode());
            } else if (e instanceof DisableLoginException) { 
                DisableLoginException ee = (DisableLoginException) e;
                aj = AjaxJson.getNotJur("Account blocked:" + ee.getDisableTime() + "Unblocked in seconds");
            } else {
                aj = AjaxJson.getError(e.getMessage());
            }

            c.result = aj;
        }
    }
}

Leave a Reply