jBeanBox 4.0.0 release, micro-Java IOC / AOP tools

jBeanBox is a micro-but features a more complete IOC / AOP tools, its own core source of only about 3000 lines, jBeanBox major JSR330 compatible and Spring annotations. jBeanBox for small projects as an alternative to Spring, or act as an open source project of IOC / AOP modules. jBeanBox for Java6 and more environmental, Home: https: //gitee.com/drinkjava2/jBeanBox


The following table is jBeanBox with Spring, Guice a comparative table on the function, red part of this update new content:  

Version 4.0.0 update details:  
1. Add the @NAMED and @QUALIFER two notes, and a corresponding increase in the corresponding Spring and JSR330 @Qualifer the @ Named, @ Qualifer annotations compatibility support.  
 See the JSR330 standard specific usage or usage on Spring @Named and @Qualifer, the only difference is jBeanBox own comments are in uppercase, of course, you can also be used directly or Spring annotations JSR, jBeanBox've come in these annotations are packaged , and without the introduction of JSR Spring or library. Java class loader has the characteristics of a first-come, if there are no special jar set, when a class is first loaded, the class of the same name that appears later will be ignored, which is why jBeanBox compatible with Spring annotations principle.  

2. Add @COMPONENT comment, and a corresponding increase in the corresponding Spring @ Service, compatibility support @ Component, @ Controller, @ Repository four annotations.  
See specific use of the use of the above-described four Spring annotations, and must be combined with the scanComponents jBeanBox class approach to scanning, and the scanning Spring class is the same, a light @Component add annotation is not enough, the class must also be open scan, discover what classes are in need of good container production. Note that this class Guice is no scanning function, loss of function. 
A scan following subclass example, in packets called parameters, there may be a plurality of spaced apart package names with commas, but each packet were allowed only a wildcard asterisk:
JBEANBOX.scanComponents (. "Com.foo *", ". com.bar *", ". . com * baz");

3. Add a PrototypeBean interfaces
   typically If a class does not have any configuration, annotated, the jBeanBox acquired its instance JBEANBOX.getBean (Foo.Class) will be a single embodiment, but if the class implements the interface PrototypeBean, jBeanBox We will always create a new instance. This feature may be used generally in the Controller, if so generated by the Controller jBeanBox, which can force each time it generates a new instance instead of returning a single embodiment.

4. Other update other small
  increase @Value Spring support, AOP allows multiple rules matched, separated by commas, create Caller cancellation method parameters. See page specific use instructions.

Another said, this update adds jBeanBox @Named and @Qualifier annotation support, but more in line with the sole purpose of standards and portability, Guice and Spring take care of the existing user habits. But I personally do not recommend the use of @Named and @Qualifier two notes, because there are more elegant implementations in jBeanBox in, see below:

//数据池配置基类
public static class HikariCPBox extends BeanBox {
   public HikariDataSource create() {
       HikariDataSource ds = new HikariDataSource();
       ds.addDataSourceProperty("cachePrepStmts", true);
       ds.addDataSourceProperty("prepStmtCacheSize", 250);
       ds.setMaximumPoolSize(3);
       ds.setConnectionTimeout(5000);
       this.setPreDestroy("close");// jBeanBox will close pool
       return ds;
   }
}

//oracle数据池配置,继承于HikariCPBox
public static class OracleDataSourceBox extends HikariCPBox {
   {
      injectValue("jdbcUrl", "jdbc:oracle:thin:@127.0.0.1:1521:XE");
      injectValue("driverClassName", "oracle.jdbc.OracleDriver");
      injectValue("username", "root");// change to your user & password
      injectValue("password", "root888");
   }
}

//MySql数据源配置类, 继承了用户名和密码,重载了jdbcRul和driverClassName
public static class MySqlDataSourceBox extends OracleDataSourceBox {
   {
       injectValue("jdbcUrl",
           "jdbc:mysql://127.0.0.1:3306/jsqlboxtest?rewriteBatchedStatements=true&useSSL=false");
       injectValue("driverClassName", "com.mysql.jdbc.Driver");
   }
}

//Service类,有两个DataSource字段需要注入
public class SomeService{
@INJECT(MySqlDataSourceBox.class)
DataSource ds1;

@INJECT(OracleDataSourceBox.class)
DataSource ds2;
...
}

As you can see, using jBeanBox can write directly on the configuration classes in @INJECT years would be finished, plain and simple. @Named @Qualifier use or development not only troublesome, but does not support IDE to locate class configuration, maintenance is troublesome. If you do not have to believe, you can put patients with Guice or Spring write again for comparison to know.  

Guess you like

Origin www.oschina.net/news/113392/jbeanbox-4-0-0-released