What is appfuse?

Source: Internet
Author: User

I. Introduction to appfuse

Appfuse is a guiding entry-level J2EE framework developed by Matt raible. It demonstrates how to integrate popular basic frameworks such as spring, hibernate, ibatis, struts, xdcolet, and JUnit, the latest version 1.7 provides support for taperstry and JSF. At the persistent layer, appfuse uses the Hibernate O/R ing tool (http://www.hibernate.org); in terms of containers, it uses the Spring framework (http://www.springframework.org ). Users can freely choose struts, spring/MVC, webwork, taperstry, and JSF web frameworks. Use TDD to test layers and even test the W/O errors output by JSP. To simplify development, you have predefined a set of directory structures, base classes, ant tasks used to create databases, configure tomcat, and test and deploy applications. This helps you quickly generate source programs and automatically maintain some configuration files.

References:
You can download appfuseat https://appfuse.dev.java.net/and the current version is 1.7.
Appfuse references and documentation can be found in http://raibledesigns.com/wiki/Wiki.jsp? Page = appfuse.

Ii. Quick Start of appfuse framework

The main purpose of the appfuse project is to help developers reduce the work they need to do when starting a project. Follow these steps to create a project:

1. Download or check out the source code of the latest appfuse version from CVS (CVS-D: pserver: guest@cvs.dev.java.net:/CVS Co appfuse.

2. Install j2se 1.4 +, correctly set the java_home environment variable, install ant 1.6.2 +, and set the ant_home environment variable.

3. Install MySQL 3.23.x + (4.1.7 is recommended) and tomcat 4.1.x + (5.0.28 is recommended). Set the catalina_home environment variable to point to your tomcat installation directory.

Note: If you are going to use MySQL 4.1.7, you must set its default character set to the UTF-8 character set and its default table type to the InnoDB type. In other words, add the following lines to your C:/Windows/My. ini or/etc/My. CNF file:
[Mysqld]
Default-character-set = utf8
[Mysqld]
Default-table-type = InnoDB

4. Install a local SMTP server or modify mail if you already have an available SMTP server. properties (under the Web/WEB-INF/classes directory) and build. properties (in the root directory -- log4j information) points to your SMTP server-by default, it points to your local SMTP server.

5. Copy the LIB/junit3.8.1/JUnit. jar file to the $ ant_home/lib directory.

6. Run the ant New-dapp. Name = yourappname-DDB. Name = yourdbname command. This will create a directory named "yourappname.

Warning: this command is applicable to some apps. the name value will not be executed-do not use "test", any name that contains "appfuse" in it, or any name that is mixed with numbers, two passbooks (-), and so on.

7. Go to the new directory, execute the ant setup task to create a database, and release your application to the Tomcat server. Only the tasks that your root user does not have a password to create a database will work. You can also open the build. properties file to change the password of the root user as needed. If you want to perform a test and want to know if all aspects can work well, then you can execute the ant test-all task for a Comprehensive Test-of course, the premise is that when you do the test, stop the Tomcat server first.

8. Execute the ant test-Reports task. After the task is executed, a message is sent to show you how to view the generated test reports.

After you confirm that you have configured your appfuse development environment through the above steps-the next thing you need to do is to learn the Guide to learn how to use appfuse for your development.

Optional installation

If you want to use ibatis as your persistent layer framework, please take a look at the readme.txt file under the extras/ibatis directory.
If you are willing to use spring as your web layer framework, please take a look at the readme.txt file under the extras/spring directory.
If you are willing to use webwork as your web layer framework, please take a look at the readme.txt file under the extras/webwork directory.
If you want to use Tapestry as your web layer framework, please take a look at the readme.txt file under the extras/tapestry directory.
If you are willing to use JSF as your web layer framework, please take a look at the readme.txt file under the extras/JSF directory.

If you want to automatically create and test a script, you can refer to the following script:
Rm-R ../appfuse-spring
Ant New-dapp. Name = appfuse-spring-DDB. Name = ibatis
CD ../appfuse-spring
Ant install-ibatis install-springmvc
CD extras/ibatis
Ant uninstall-Hibernate
CD ../..
Ant setup
Ant test-all test-Reports

If you do not want to install ibatis, spring MVC or webwork, you should delete the installation content in the extras directory before you put your project into the code control repository.

--------------------------------------------------------------------------------

Generally, after you complete all the above steps and make them work, the most likely thing is that you want. appfuse package name, which is similar to "com. company. Now it is very easy to do this. All you need to do is download a tool to change the package name and check its readme file to learn about its installation and use.

Note: before using this tool, you 'd better back up your project to ensure it can be restored.

If you set Org. appfuse. webapp. the form package is changed to test. web. for the package name such as form, you must modify the converterutil class in the src/service package at the same time. The getopposingobject method is your friend. Let's take a look:

Name = stringutils. Replace (name, "model", "webapp. Form ");
Name = stringutils. Replace (name, "webapp. Form", "model ");

Iii. appfuse Development Guide

If you have downloaded the appfuse and want to install it on your machine, follow the steps in quick start to install it. Once you have installed all the content, the following guide is the best tutorial for you to learn how to use appfuse for development.

Note: This Development Guide also contains a copy in the appfuse release version. If you want to update the copy in your project (it is in the docs directory ), you can execute "ant wiki.

For appfuse 1.6.1, you can tell you how to generate most of the Code in this Guide. If you are using a combination of STRUTS + hibernate, you can even generate them completely. However, if your web layer framework chooses spring or webwork, it is not so lucky. It is difficult for them to write an automated installation script, so you have to configure those controllers and actions by yourself. This is mainly because I did not use XDoclet for these web layer frameworks, but also because of the limitations of using ant as the Installation tool. The tool that automatically generates code is called appgen. I will explain how to use it in part I.

Part I: Create a New daos and object in appfuse-this is a tutorial on how to create a data-based Java object for the medium table and how to create a Java class to persist the object to the database.

1. About this guide:

This guide will show you how to create a new table in the database and how to create Java code to access the table.

We will create an object and some other classes to save (save, load, delete) the object to the database. In Java, we call this object a pojo object (plain old Java object). This object basically corresponds to a table in the database, other classes will be:

A Data Access Object (also known as a DaO), an interface, and a hibernate implementation class.
A JUnit class is used to test whether our Dao object can work correctly.
Note: If you are using MySQL and you want to use transactions (generally you will definitely choose to use), you must set table-type to InnoDB. You can add the following content to your MySQL configuration file (/etc/My. CNF or C:/Windows/My. INI. The second setting (used to set the UTF-8 Character Set) is required by MySQL 4.1.7 +.

[Mysqld]
Default-table-type = InnoDB
Default-character-set = utf8

If you encounter batch obfuscation errors using PostgreSQL, try to add them to your src/Dao/**/hibernate/applicationContext-hibernate.xml File

0 to disable batch processing.

Appfuse uses hibernate as its default persistent layer. Hibernate is an object relationship ing framework that enables you to build a ing between your Java object and the database table. This allows you to easily execute CRUD (create, retrieve, update, delete) operations on your objects.

You can also use ibatis as another possible choice for the persistent layer. If you want to install ibatis in appfuse, take a look at the readme.txt file in the extras/ibatis directory. If you want to replace hibernate with ibatis, I hope you have enough reason and you should be familiar with it. I also hope that you can make good suggestions on how to use ibatis in appfuse for this guide.

Below I will use text to show you how I did it in the actual development process.
Let's start by creating a new object, a Dao and a test case in the appfuse project structure.

Content list

[1] Create a new object and add the XDoclet tag
[2] Use ant to create a new database table based on the newly created object
[3] Create a New daotest for JUnit testing of Dao
[4] Create a New Dao and perform the CRUD operation on this object.
[5] configure the spring configuration file for the person object and persondao
[6] Run daotest for testing

[1] Create a new object and add the XDoclet tag

The first thing we need to do is to create an object to persist it. Let's create a simple "person" Object (created to the src/Dao/**/model directory), and let it have an ID, one firstname and one lastname (as the property of this object ).

Package org. appfuse. model;

Public class person extends baseobject {
Private long ID;
Private string firstname;
Private string lastname;

/*
Generate your getters and setters using your favorite ide:
In eclipse:
Right-click-> source-> Generate getters and setters
*/
}

This class should inherit from baseobject, because baseobject has three Abstract METHODS: (equals (), hashcode () and tostring ()), therefore, you must implement them in this person class. The first two methods are required by hibernate. The simplest method is to use a tool (such as commonclipse) to complete it, if you want more information about using this tool, go to Lee grey's website. Another tool you can use is commons4e, which is an Eclipse plug-in that I have never used, so I cannot tell you what functions it has.

If you are using intellij idea, you can generate equals () and hashcode (), but cannot generate tostring (). Of course, there is a tostringplugin, but I have never used it myself.

Now we have a created pojo. We need to add the XDoclet tag to it to generate the hibernate ing file. This ing file allows hibernate to map objects to tables and ing attributes to columns of tables.

First, we add a @ hibernate. Class tag, which tells hibernate which table the object will map:

/**
* @ Hibernate. Class table = "person"
*/
Public class person extends baseobject {

We must also add a primary key ing. Otherwise, XDoclet will encounter an error when the ing file is generated. Note that all these @ hibernate. * labels should be placed in the javadocs location of the getter method of your pojo object.

/**
* @ Return returns the ID.
* @ Hibernate. ID column = "ID"
* Generator-class = "increment" unsaved-value = "null"
*/

Public long GETID (){
Return this. ID;
}

I used generator-class = "increment" to replace generate-class = "native" because I found some problems when using "native" in other databases. If you only plan to use MySQL, we recommend that you use "native", and our guide uses "increment ".

[2] Use ant to create a new database table based on the newly created object

You can run "ant setup-DB" to create the person table. This task creates the person. HBM. xml file and a "person" table in the database. From the ant console, you can see the table model created by hibernate for you:

[Schemaexport] Create Table person (
[Schemaexport] ID bigint not null,
[Schemaexport] primary key (ID)
[Schemaexport]);

If you want to take a look at the content of the person. HBM. xml file generated by hibernate for you, you can go to the build/Dao/GEN/**/model directory to see it. Below I will list its content:

 

"-// Hibernate/hibernate mapping DTD 2.0 // en"
Http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd>



Name = "org. appfuse. model. Person"
Table = "person"
Dynamic-update = "false"
Dynamic-insert = "false"
>

Name = "ID"
Column = "ID"
Type = "Java. Lang. Long"
Unsaved-value = "null"
>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.