Another small and beautiful Java development framework: New Solon 1.2

After Solon 1.2 was released, the X class name prefix was removed. So make some adjustments to this article.

Solon is a new and easy-to-use Java development framework in the Java world. Refer to the design of many existing frameworks such as Javalin and Spring boot.

Named from the character "Sauron" in One Piece, saying that he hopes to be able to play like him

  • small. It's really small. The smallest Http operating unit is only 0.1m. Even if there are templates, jdbc, and logs, put them in. . . Estimated 2m-5m will be done
  • Good performance. Under the QPS test of Hello World, it is basically about twice as high as Spring boot
  • Simple and convenient. It is basically close to the experience of Spring mvc, and it is quick to start.

The officially supported jdk version is: 8.0-15. Basically all released...

@Controller
public class HelloworldApp {
    
    
    public static void main(String[] args) {
    
    
        Solon.start(HelloworldApp.class, args);
    }

    @Mapping("/")
    public String helloworld(){
    
    
        return "Hello world!";
    }
}

Is it a familiar feeling? The experience is very similar to Spring boot mvc.

public class HelloworldApp {
    
    
    public static void main(String[] args) {
    
    
        SolonApp app = Solon.start(HelloworldApp.class, args);

        var map = new HashMap<String, Integer>();
        map.put("val1", 1);
        map.put("val2", 2);

        app.get("/", ctx -> ctx.output("Hello World"));
        app.get("/json/map", ctx -> ctx.render(map));
        
        app.after("**",  ctx -> {
    
    
            System.out.println("log::");
            System.out.println(ctx.attr("output", ""));
        });
    }
}

Is it very simple? The above two can be mixed. . . Especially to add a post-processing, it is really convenient. Put some more code:

//启动参数加-debug=1 ,打印所有异常
//
app.onError((err)->{
    
    
  if(Solon.cfg().isDebugMode()){
    
    
      
      err.printStackTrace();
  }
})
//多数据源的配置(配置可以注入,也可以直接取)
//
@Configuration
public class Config {
    
    
    @Bean("db1")
    public DataSource db1(@Inject("${test.db1}") HikariDataSource dataSource) {
    
    
        return dataSource;
    }

    @Bean("db2")
    public DataSource db2(@Inject("${test.db2}") HikariDataSource dataSource) {
    
    
        return dataSource;
    }
}

If you are a Java programmer and have never used a WEB framework other than Spring-web, maybe you can try Solon!

Attachment: Solon project address

Guess you like

Origin blog.csdn.net/cwzb/article/details/111941868