内容简介:jboot 1.0-alphpa1 发布,类似 springboot 的开源框架
jboot
jboot是一个基于jfinal、undertow开发的一个类似springboot的开源框架, 我们已经在正式的商业上线项目中使用。她集成了代码生成,微服务,MQ,RPC,监控等功能, 开发者使用及其简单。
maven dependency
<dependency> <groupId>io.jboot</groupId> <artifactId>jboot</artifactId> <version>1.0-alphpa1</version> </dependency>
controller example
new a controller
@UrlMapping(url="/") public class MyController extend JbootController{ public void index(){ renderText("hello jboot"); } }
start
public class MyStarter{ public static void main(String [] args){ Jboot.run(args); } }
visit: http://127.0.0.1:8088
mq example
config jboot.properties
#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
Jboot.getMq().publish(yourObject, toChannel);
server b message listener
Jboot.getMq().addMessageListener(new JbootmqMessageListener(){ @Override public void onMessage(String channel, Object obj) { System.out.println(obj); } }, channel);
rpc example
config jboot.properties
#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
public interface HelloService { public String hello(String name); }
server a export serviceImpl
@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
HelloService service = Jboot.service(HelloService.class); service.hello("michael");
cache example
config jboot.properties
#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
Jboot.getCache().put("cacheName", "key", "value");
database access example
config jboot.properties
#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
@Table(tableName = "user", primaryKey = "id") public class User extends JbootModel<User> { }
dao query
public class UserDao { public static find User DAO = new User(); public User findById(String id){ return DAO.findById(id); } public List<User> findByNameAndAge(String name,int age){ return DAO.findListByColums(Columns.create().like("name","%"+name+"%").gt("age",age)); } }
event example
send event
Jboot.sendEvent(actionStr, dataObj)
event listener
@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
jboot.myconfig.user = aaa jboot.myconfig.password = bbb
define config model
@PropertieConfig(prefix = "jboot.myconfig") public class MyConfig { private String name; private String password; // getter and setter }
get config model
MyConfig config = Jboot.config(MyConfig.class); System.out.println(config.getName());
code generator
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
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>appassembler-maven-plugin</artifactId> <version>1.10</version> <configuration> <assembleDirectory>${project.build.directory}/app</assembleDirectory> <repositoryName>lib</repositoryName> <binFolder>bin</binFolder> <configurationDirectory>webRoot</configurationDirectory> <copyConfigurationDirectory>true</copyConfigurationDirectory> <configurationSourceDirectory>src/main/resources</configurationSourceDirectory> <repositoryLayout>flat</repositoryLayout> <encoding>UTF-8</encoding> <logsDirectory>logs</logsDirectory> <tempDirectory>tmp</tempDirectory> <programs> <program> <mainClass>io.jboot.Jboot</mainClass> <id>jboot</id> <platforms> <platform>windows</platform> <platform>unix</platform> </platforms> <jvmSettings> <extraArguments> <extraArgument>-server</extraArgument> <extraArgument>-Xmx2G</extraArgument> <extraArgument>-Xms2G</extraArgument> </extraArguments> </jvmSettings> </program> </programs> </configuration> </plugin> </plugins> </build>
maven build
mvn package appassembler:assemble
start app
cd yourProjectPath/target/app/bin ./jboot
start app and change config
cd yourProjectPath/target/app/bin ./jboot --jboot.server.port=8080 --jboot.rpc.type=local
use your properties replace jboot.properties
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
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- 开源 | Hippy:腾讯开源的跨端开发框架
- WeGeek | WePY 开源框架
- 开源 | vnpy:基于 Python 的开源量化交易平台开发框架
- 优秀开源框架的扩展机制实现
- 开源Botnet框架Byob分析
- 滴滴开源小程序框架 Mpx
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
马化腾自述-我的互联网思维
赵黎 / 石油工业出版社 / 2014-8-1 / 35
马化腾自述:我的互联网思维》讲述了些人说移动互联网就是加了“移动”两个字,互联网十几年了,移动互联网应该是个延伸。我的感受是,移动互联网远远不只是一个延伸,甚至是一个颠覆。互联网是一个开放交融、瞬息万变的大生态,企业作为互联网生态里面的物种,需要像自然界的生物一样,各个方面都具有与生态系统汇接、和谐、共生的特性。开放和分享并不是一个宣传口号,也不是一个简单的概念。开放很多时候被看作一种姿态,但是我......一起来看看 《马化腾自述-我的互联网思维》 这本书的介绍吧!