|
| 1 | +# ACT Framework |
| 2 | + |
| 3 | +[](https://gitter.im/actframework/actframework?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) |
| 4 | + |
| 5 | +## 新闻 |
| 6 | +* 一个ActFramework版本的[TodoBackend](http://www.todobackend.com/)项目: http://github.com/greenlaw110/todomvc-act |
| 7 | +* Actframework 正式登录[码云](https://git.oschina.net/actframework/actframework)以及[开源中国](http://www.oschina.net/p/actframework) |
| 8 | +* [TechEmpower Benchmark](https://www.techempower.com/benchmarks/)接受了 |
| 9 | +Actframework [性能测试项目](https://github.com/TechEmpower/FrameworkBenchmarks/tree/master/frameworks/Java/act) |
| 10 | +期待看到Act在即将来到的TechEmpower第14轮测试的表现 |
| 11 | +* 一个三方的[性能测试](https://github.com/networknt/microservices-framework-benchmark)显示Act在简单情况下的性能 |
| 12 | + 是Spring-boot的20倍 |
| 13 | + |
| 14 | +## 项目状态 |
| 15 | + |
| 16 | +* 当前稳定版本: 0.6.0-SNAPSHOT |
| 17 | +* 第一个正式版预计在2017年三月发行 |
| 18 | + |
| 19 | +## 安装 |
| 20 | + |
| 21 | +将下面的依赖添加进你的`pom.xml`文件 |
| 22 | + |
| 23 | +```xml |
| 24 | + <dependency> |
| 25 | + <groupId>org.actframework</groupId> |
| 26 | + <artifactId>act</artifactId> |
| 27 | + <version>0.6.0-SNAPSHOT</version> |
| 28 | + </dependency> |
| 29 | +``` |
| 30 | + |
| 31 | +因为现在还是使用快照版发行,您还需要在`pom.xml`文件中加入下面的代码: |
| 32 | + |
| 33 | +```xml |
| 34 | + <parent> |
| 35 | + <groupId>org.sonatype.oss</groupId> |
| 36 | + <artifactId>oss-parent</artifactId> |
| 37 | + <version>7</version> |
| 38 | + </parent> |
| 39 | +``` |
| 40 | + |
| 41 | +## 特性 |
| 42 | + |
| 43 | +* **全栈式MVC框架** |
| 44 | + * Actframework**不是**一个servlet框架. Act应用不需要servlet容器, 而是作为一个独立的Java应用程序运行. |
| 45 | + 一般可以在数秒之内启动 |
| 46 | + |
| 47 | +* **无与伦比的开发体验与高性能** |
| 48 | + * 一旦开始开发就无需重启服务器. Act的dev模式提供的热加载功能是每个Java开发员的梦想. |
| 49 | + 看看[这个三分钟的视频演示](https://www.youtube.com/watch?v=68Z-jTL6fDg)来体验一下把! |
| 50 | + * [这个第三方性能测试](https://github.com/networknt/microservices-framework-benchmark)展示了Act的强劲性能 |
| 51 | + 在简单的情况下Act可以获得Spring-boot20倍以上的吞吐量 |
| 52 | + |
| 53 | +* **完整的JSR330依赖注入支持** |
| 54 | + * ActFramework's DI support is built on top of [Genie](https://github.com/osglworks/java-di), a lightweight |
| 55 | + yet [fast](https://github.com/greenlaw110/di-benchmark) JSR330 implementation. |
| 56 | + * Benefit from Act's powerful class scan feature, it does not require the user to create injector from |
| 57 | + modules (as the usually way you use Guice). Declare your module and your binding is automatically registered |
| 58 | + |
| 59 | +* **Superb SPA/Mobile app support** |
| 60 | + * [Awesome JSON/RESTful support](https://www.youtube.com/watch?v=B2RRSzYeo8c&t=4s) |
| 61 | + * [Built-in CORS support](http://actframework.org/doc/configuration.md#cors) |
| 62 | + * [Session/Header mapping](http://actframework.org/doc/configuration#session_mapper_impl) so you are not limited to cookie |
| 63 | + |
| 64 | +* **Uncompromising Security** |
| 65 | + * Session cookie is secure and http only, payload is signed and encrypted (optionally) |
| 66 | + * [Enable CSRF prevention with just one configuration item](http://actframework.org/doc/configuration.md#csrf) |
| 67 | + * XSS prevention: the default Rythm engine [escape variable output](http://fiddle.rythmengine.org/#/editor/398e71d927234f13a26bb346376141ce) by default |
| 68 | + * Implementing your authentication/authorisation/accounting framework using [AAA plugin](https://github.com/actframework/act-aaa-plugin) |
| 69 | + |
| 70 | +* **Annotation aware but not annotation stack** |
| 71 | + * Annotation is one of the tool ActFramework used to increase expressiveness. However |
| 72 | + we do not appreciate [crazy annotation stacked code](http://annotatiomania.com/). |
| 73 | + Instead we make the code to express the intention in a natural way and save |
| 74 | + the use of annotation whenever possible. |
| 75 | + |
| 76 | + For example, for the following SpringMVC code: |
| 77 | + ```java |
| 78 | + @RequestMapping(value="/user/{userId}/invoices", method = RequestMethod.GET) |
| 79 | + public List listUsersInvoices( |
| 80 | + @PathVariable("userId") int user, |
| 81 | + @RequestParam(value = "date", required = false) Date dateOrNull) { |
| 82 | + ... |
| 83 | + } |
| 84 | + ``` |
| 85 | + The corresponding ActFramework app code is: |
| 86 | + ```java |
| 87 | + @GetAction("/user/{user}/invoices") |
| 88 | + public List listUsersInvoices(int user, Date date) { |
| 89 | + ... |
| 90 | + } |
| 91 | + ``` |
| 92 | + |
| 93 | +* **Multi-environment configuration** |
| 94 | + * ActFramework supports the concept of `profile` which allows you to organize your configurations |
| 95 | + in different environment (defined by profile) easily. Take a look at the following |
| 96 | + configurations from one of our real project: |
| 97 | + |
| 98 | + ```text |
| 99 | + resources |
| 100 | + ├── conf |
| 101 | + │ ├── common |
| 102 | + │ │ ├── app.properties |
| 103 | + │ │ ├── db.properties |
| 104 | + │ │ ├── mail.properties |
| 105 | + │ │ ├── payment.properties |
| 106 | + │ │ └── social.properties |
| 107 | + │ ├── local-no-ui |
| 108 | + │ │ ├── app.properties |
| 109 | + │ │ ├── db.properties |
| 110 | + │ │ └── port.properties |
| 111 | + │ ├── local-sit |
| 112 | + │ │ └── app.properties |
| 113 | + │ ├── local-ui |
| 114 | + │ │ ├── app.properties |
| 115 | + │ │ └── db.properties |
| 116 | + │ ├── sit |
| 117 | + │ │ ├── app.properties |
| 118 | + │ │ └── db.properties |
| 119 | + │ └── uat |
| 120 | + ... |
| 121 | + ``` |
| 122 | + Suppose on your UAT server, you start the application with JVM option `-Dprofile=uat`, |
| 123 | + ActFramework will load the configuration in the following sequence: |
| 124 | + 1. Read all `.properties` files in the `/resources/conf/common` dir |
| 125 | + 2. Read all `.properties` files in the `/resources/conf/uat` dir |
| 126 | + |
| 127 | + This way ActFramework use the configuration items defined in `uat` profile to overwrite |
| 128 | + the same items defined in `common` profile. The common items that are not overwritten |
| 129 | + still effective. |
| 130 | + |
| 131 | +* **[Simple yet powerful database support](http://actframework.org/doc/model.md)** |
| 132 | + * [Multiple database support built in](http://actframework.org/doc/multi_db.md) |
| 133 | + |
| 134 | +* **[Powerful view architecture with multiple render engine support](http://actframework.org/doc/templating.md)** |
| 135 | + |
| 136 | +* **Commonly used tools** |
| 137 | + * [Sending email](http://actframework.org/doc/email) |
| 138 | + * [Schedule jobs](http://actframework.org/doc/job) |
| 139 | + * [Event handling and dispatching](http://actframework.org/doc/event) |
| 140 | + |
| 141 | +## Sample code |
| 142 | + |
| 143 | +### A HelloWorld app |
| 144 | + |
| 145 | +```java |
| 146 | +package demo.helloworld; |
| 147 | + |
| 148 | +import act.Act; |
| 149 | +import act.Version; |
| 150 | +import org.osgl.mvc.annotation.GetAction; |
| 151 | + |
| 152 | +public class HelloWorldApp { |
| 153 | + |
| 154 | + @GetAction |
| 155 | + public String sayHello() { |
| 156 | + return "Hello World!"; |
| 157 | + } |
| 158 | + |
| 159 | + public static void main(String[] args) throws Exception { |
| 160 | + Act.start("Hello World", Version.appVersion(), HelloWorldApp.class); |
| 161 | + } |
| 162 | + |
| 163 | +} |
| 164 | +``` |
| 165 | + |
| 166 | +See [this 7 mins video on how to create HelloWorld in Eclipse from scratch](https://www.youtube.com/watch?v=_IhRv3-Ejfw). |
| 167 | +or [for users without youtube access](http://www.tudou.com/programs/view/fZqqkFacfzA/) |
| 168 | + |
| 169 | +### A full RESTful service |
| 170 | + |
| 171 | +```java |
| 172 | +package demo.rest; |
| 173 | + |
| 174 | +import act.controller.Controller; |
| 175 | +import act.db.morphia.MorphiaAdaptiveRecord; |
| 176 | +import act.db.morphia.MorphiaDao; |
| 177 | +import org.mongodb.morphia.annotations.Entity; |
| 178 | +import org.osgl.mvc.annotation.*; |
| 179 | + |
| 180 | +import java.util.Map; |
| 181 | + |
| 182 | +import static act.controller.Controller.Util.notFoundIfNull; |
| 183 | + |
| 184 | +@Entity("user") |
| 185 | +public class User extends MorphiaAdaptiveRecord<User> { |
| 186 | + |
| 187 | + @Controller("user") |
| 188 | + public static class Service extends MorphiaDao<User> { |
| 189 | + |
| 190 | + @PostAction |
| 191 | + public User create(User user) { |
| 192 | + return save(user); |
| 193 | + } |
| 194 | + |
| 195 | + @GetAction |
| 196 | + public Iterable<User> list() { |
| 197 | + return findAll(); |
| 198 | + } |
| 199 | + |
| 200 | + @GetAction("{id}") |
| 201 | + public User show(String id, Map<String, Object> data) { |
| 202 | + return findById(id); |
| 203 | + } |
| 204 | + |
| 205 | + @PutAction("{id}") |
| 206 | + public User update(String id, Map<String, Object> data) { |
| 207 | + User user = findById(id); |
| 208 | + notFoundIfNull(user); |
| 209 | + user.mergeValues(data); |
| 210 | + return save(user); |
| 211 | + } |
| 212 | + |
| 213 | + @DeleteAction("{id}") |
| 214 | + public void delete(String id) { |
| 215 | + deleteById(id); |
| 216 | + } |
| 217 | + } |
| 218 | + |
| 219 | + public static void main(String[] args) throws Exception { |
| 220 | + Act.start("RESTful Demo", Version.appVersion(), User.class); |
| 221 | + } |
| 222 | + |
| 223 | +} |
| 224 | +``` |
| 225 | + |
| 226 | +See [this 1 hour video on RESTful support](https://www.youtube.com/watch?v=B2RRSzYeo8c&t=4s) |
| 227 | +or [for user without youtube access](http://www.tudou.com/programs/view/K9ayRYIJNhk/) |
| 228 | + |
| 229 | + |
| 230 | +See [this 7 mins video to understand more about AdaptiveRecord](https://www.youtube.com/watch?v=gWisqi-bp0M&t=1s) |
| 231 | +or [for user without youtube access](http://www.tudou.com/programs/view/o4Up0B4wD8Y/) |
| 232 | + |
| 233 | +## Background |
| 234 | + |
| 235 | +I love PlayFramework v1.x because it is simple, clear and expressive. It brought us a completely different experience |
| 236 | +in web development with Java. However I don't totally agree with where Play 2.X is heading for, and it looks like I am |
| 237 | +not the only person with the concern as per this |
| 238 | +[open letter to Play Framework Developers](https://groups.google.com/d/msg/play-framework/AcZs8GXNWUc/IanbqC-c-MkJ). |
| 239 | +
|
| 240 | +I [have thought of](http://software-lgl.blogspot.com.au/2012/12/thinking-about-creating-new-java-web.html) rolling out |
| 241 | +something that could follow the road paved by Play 1.x, something that is simple, clear, expressive and Java |
| 242 | +(specifically) developer friendly. About one and half year after that I decide I could start the project seriously, |
| 243 | +and now another one and half year passed by, I've got this ACT framework in a relatively good shape. |
| 244 | + |
| 245 | +Happy coding! |
0 commit comments