Solonは、Springbootに似たマイクロ開発フレームワークです。プロジェクトが2018年に開始されて以来、多くの以前の作品が参照されています。2年と3,500を超えるコミットが必要でした。カーネルは、0.1mの数値、超高Web実行スコア、および優れたユーザーエクスペリエンスを維持しています。
ソロンは、抑制+シンプルさ+開放性の原則を強調し、より小さく、より速く、より自由な体験を目指しています。
いわゆる小さい:
カーネルは0.1m、最小のWeb開発ユニットは0.2mです(Springbootプロジェクトパッケージと比較すると、非常に小さいため無視できます)
いわゆる高速:
ローカルのhelloworldテストであるQpsは、最大120,000に達する可能性があります。参照できます: " helloworld_wrk_test "
いわゆるより自由:(自由なコード操作)
// 除了注入模式之外,还可以按需手动
//
//手动获取配置
Map<String,String> db = Solon.cfg().getMap("db");
//手动获取容器里的Bean
UserService userService = Aop.get(UserService.class);
//手动监听http post请求
Solon.global().post("/user/update", x-> userService.updateById(x.paramMap()));
このバージョンでの主な変更点:
1.プラグインを追加します:springboot-solon-plugin(Springbootとの相互運用性を実現するため)
- サイズ約0.1mのフレームをご紹介します
<dependency>
<groupId>org.noear</groupId>
<artifactId>springboot-solon-plugin</artifactId>
<version>1.2.13</version>
</dependency>
Solonの他のプラグインをインポートする必要がある場合、Solonはより小さなフレームワークに適応しますか?
- Springbootシステムに組み込んだ後、2つのフレームワークのコンテナリソースと機能を同時に使用するか、移行期間中にそれらを一時的に混合します
1)アプリケーションを起動します
@SpringBootLinkSolon
@SpringBootApplication
public class DemoApp {
public static void main(String[] args) {
//先
Solon.start(DemoApp.class, args);
//后
SpringApplication.run(DemoApp.class, args);
}
}
2)Springboogコンポーネントを定義する
public interface HelloService {
String hello(String name);
}
//此处为Springboot的注解(Solon 也有同名的注解)
@Component
public class HelloServiceImp implements HelloService {
@Override
public String hello(String name) {
return "hello: " + name;
}
}
3)SolonクラスのSpringbootコンテナのコンポーネントを使用します
//此处为Solon的注解(Springboot 也有同名的注解)
@Controller
public class SolonController {
//使用Solon注解,将Springboot bean注入到Solon的托管类中
@Inject
HelloService helloService;
//注入配置
@Inject("${user.name}")
String name;
@Mapping("/test")
public String home(String msg) throws Exception {
return "solon: " + helloService.hello();
}
}
4)SpringbootクラスでSolonの手書き機能を使用する
@RestController
public class Text2Controller {
HelloService helloService;
@RequestMapping("/test2")
public String home(String msg) throws Exception {
//使用Solon的手写特性赋值,进行懒加载
//
if(helloService == null){
helloService = Aop.get(HelloService.class);
}
//手动获取配置
//
String name = Solon.cfg().get("user.name");
//也可以动态增加一个请求监听
//
//Solon.global().get("/hello",(c)->c.output("Hello world!"));
return "springboot: " + helloService.hello(name);
}
}
?上記はデモンストレーション効果のみを目的としており、実際のシーンと一致しない場合がありますか?
2.サードパーティの構成および登録サービス、領事フレームワークに適応します:consul-solon-plugin
- このフレームワークは、Solonの最初のコミュニティ貢献であるコミュニティ開発者によって提供されています。。。どうもありがとうございました
1)構成例
solon.app.name=test-consul-api
solon.app.group=test
consul.host=localhost
#consul.port=8500
#consul.token=
#consul.discovery.enable=true
#consul.discovery.hostname=12.12.12:12
#consul.discovery.tags=dev
#consul.discovery.healthCheckInterval=10s
#consul.discovery.healthCheckPath=/run/check/
consul.discovery.healthDetector=jvm,cpu,memory,disk,qps,os
#consul.locator.enable=true
#consul.locator.interval=10000
#consul.config.enable=true
#consul.config.key=test
consul.config.watch=config/,gateway/
#consul.config.interval=10000
2)使用例
@Controller
public class HelloController {
//使用了consul的注册与发现服务
//
@NamiClient("test-consul-api:/")
HelloInterface helloInterface;
@Mapping("/hello")
public String sayHello() {
//consul的配置内容集成到Solon的配置体系,可注入,可手动获取
//
return "config:" + Solon.cfg().get("hello")+",rpc:"+helloInterface.hello0();
}
}