# jboot
**Repository Path**: envan/jboot
## Basic Information
- **Project Name**: jboot
- **Description**: jboot是一个基于jfinal、undertow开发的一个类似springboot的开源框架, 我们已经在正式的商业上线项目中使用。
- **Primary Language**: Java
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 948
- **Created**: 2017-06-08
- **Last Updated**: 2020-12-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# jboot
jboot is a similar springboot project base on jfinal and undertow,we have using in product environment.
# jboot 中文描述
jboot是一个基于jfinal、undertow开发的一个类似springboot的开源框架,
我们已经在正式的商业上线项目中使用。她集成了代码生成,微服务,MQ,RPC,监控等功能,
开发者使用及其简单。
# maven dependency
```xml
io.jboot
jboot
1.0-alphpa1
```
# controller example
new a controller
```java
@UrlMapping(url="/")
public class MyController extend JbootController{
public void index(){
renderText("hello jboot");
}
}
```
start
```java
public class MyStarter{
public static void main(String [] args){
Jboot.run(args);
}
}
```
visit: http://127.0.0.1:8088
# mq example
config jboot.properties
```java
#type default redis (support: redis,activemq,rabbitmq,hornetq,aliyunmq )
jboot.mq.type = redis
jboot.mq.redis.address = 127.0.0.1
jboot.mq.redis.password =
jboot.mq.redis.database =
```
server a sendMqMessage
```java
Jboot.getMq().publish(yourObject, toChannel);
```
server b message listener
```java
Jboot.getMq().addMessageListener(new JbootmqMessageListener(){
@Override
public void onMessage(String channel, Object obj) {
System.out.println(obj);
}
}, channel);
```
# rpc example
config jboot.properties
```java
#type default motan (support:local,motan,grpc,thrift)
jboot.rpc.type = motan
jboot.rpc.requestTimeOut
jboot.rpc.defaultPort
jboot.rpc.defaultGroup
jboot.rpc.defaultVersion
jboot.rpc.registryType = consul
jboot.rpc.registryName
jboot.rpc.registryAddress = 127.0.0.1:8500
```
define interface
```java
public interface HelloService {
public String hello(String name);
}
```
server a export serviceImpl
```java
@JbootrpcService(export = HelloService.class)
public class myHelloServiceImpl extends JbootService implements HelloService {
public String hello(String name){
System.out.println("hello" + name);
return "hello ok";
}
}
```
server b call
```java
HelloService service = Jboot.service(HelloService.class);
service.hello("michael");
```
# cache example
config jboot.properties
```java
#type default ehcache (support:ehcache,redis,ehredis (ehredis:tow level cache,ehcache level one and redis level tow))
jboot.cache.type = redis
jboot.cache.redis.address =
jboot.cache.redis.password =
jboot.cache.redis.database =
```
use cache
```java
Jboot.getCache().put("cacheName", "key", "value");
```
# database access example
config jboot.properties
```java
#type default mysql (support:mysql,oracle,db2...)
jboot.datasource.type=
jboot.datasource.url=
jboot.datasource.user=
jboot.datasource.password=
jboot.datasource.driverClassName=
jboot.datasource.connectionInitSql=
jboot.datasource.cachePrepStmts=
jboot.datasource.prepStmtCacheSize=
jboot.datasource.prepStmtCacheSqlLimit=
```
define model
```java
@Table(tableName = "user", primaryKey = "id")
public class User extends JbootModel {
}
```
dao query
```java
public class UserDao {
public static find User DAO = new User();
public User findById(String id){
return DAO.findById(id);
}
public List findByNameAndAge(String name,int age){
return DAO.findListByColums(Columns.create().like("name","%"+name+"%").gt("age",age));
}
}
```
# event example
send event
```java
Jboot.sendEvent(actionStr, dataObj)
```
event listener
```java
@EventConfig(action = {User.ACTION_ADD,User.ACTION_DELETE})
public class MyEventListener implements JbootEventListener {
public void onMessage(JbootEvent event){
if(event.getAction.equals(User.ACTION_ADD)){
System.out.println("new user add, user:"+event.getData);
}else if(event.getAction.equals(User.ACTION_DELETE)){
System.out.println("user deleted, user:"+event.getData);
}
}
}
```
# read config
config jboot.properties
```java
jboot.myconfig.user = aaa
jboot.myconfig.password = bbb
```
define config model
```java
@PropertieConfig(prefix = "jboot.myconfig")
public class MyConfig {
private String name;
private String password;
// getter and setter
}
```
get config model
```java
MyConfig config = Jboot.config(MyConfig.class);
System.out.println(config.getName());
```
# code generator
```java
public static void main(String[] args) {
String modelPackage = "io.jboot.test";
String dbHost = "127.0.0.1";
String dbName = "yourDbName";
String dbUser = "root";
String dbPassword = "";
JbootModelGenerator.run(modelPackage, dbHost, dbName, dbUser, dbPassword);
}
```
# build
config pom.xml
```xml
org.apache.maven.plugins
maven-compiler-plugin
1.8
1.8
org.codehaus.mojo
appassembler-maven-plugin
1.10
${project.build.directory}/app
lib
bin
webRoot
true
src/main/resources
flat
UTF-8
logs
tmp
io.jboot.Jboot
jboot
windows
unix
-server
-Xmx2G
-Xms2G
```
maven build
```java
mvn package appassembler:assemble
```
# start app
```java
cd yourProjectPath/target/app/bin
./jboot
```
start app and change config
```java
cd yourProjectPath/target/app/bin
./jboot --jboot.server.port=8080 --jboot.rpc.type=local
```
use your properties replace jboot.properties
```java
cd yourProjectPath/target/app/bin
./jboot --jboot.model=dev --jboot.server.port=8080
```
use jboot-dev.proerties replace jboot.properties and set jboot.server.port=8080
# thanks
rpc framework:
* motan(https://github.com/weibocom/motan)
* grpc(http://grpc.io)
* thrift(https://github.com/apache/thrift)
mq framework:
* activemq
* rabbitmq
* redis mq
* hornetq
* aliyun mq
cache framework
* ehcache
* redis
core framework:
* jfinal
* undertow
# author
* name:yangfuhai
* qq:1506615067
* email:fuhai999@gmail.com
# donate
