Webwork2 + spring + hibernate getting started full Configuration Guide (1) (original)

Source: Internet
Author: User

Webwork is an excellent open-source framework, especially its interceptor mechanism. I think it is the biggest highlight of the entire system. I can write a lot of articles on it.
My development environment is eclipse3.0.1 + lomoz, and my database is mysql4.0.12. Of course, mysqlcc is also used, and my servers are atat4.0.3 and tomcat4.1.
Download webwork., spring., and hibernate first, and put the JAR file in the lib directory of web-INF. Also, download the http://unc.dl.sourceforge.net/sourceforge/aopalliance/aopalliance.zip and put aopalliance. jar in the lib directory.
There are webwork2-spring.jar, and MySQL driver to download and put in Lib, indispensable
Then configure log4j. If the log is not correctly configured, Tomcat will not be able to publish your project normally. It is easy to configure log4j,
Create a log4j. properties file under Web-INF/classes. The content is as follows:
Log4j. rootlogger = info, A1, R
Log4j. appender. A1 = org. Apache. log4j. leleappender
Log4j. appender. a1.layout = org. Apache. log4j. patternlayout
Log4j. appender. a1.layout. conversionpattern = %-d {yyyy-mm-dd hh: mm: SS} [% C]-[% P] % m % N
Log4j. appender. r = org. Apache. log4j. rollingfileappender
Log4j. appender. R. File = D:/Tomcat 4.1/webapps/demo/logs/log4j. Log
Log4j. appender. R. maxfilesize = 100kb
Log4j. appender. R. maxbackupindex = 1
Log4j. appender. R. layout = org. Apache. log4j. patternlayout
Log4j. appender. R. layout. conversionpattern = % P % T % C-% m % N
Log4j. appender. r. for details about log4j, we recommend that you read Hilton's study notes and related articles on the IBM website.
Now, let's start our webwork journey. First, configure the Web. xml file
<? XML version = "1.0"?>
<! Doctype web-app public "-// Sun Microsystems, Inc. // DTD web application 2.3 //" http://java.sun.com/dtd/web-app_2_3.dtd ">

<! -- Copyright (c) 2002 by objectlearn. All Rights Reserved. -->
<Web-app>
<Listener>
<Listener-class> org. springframework. Web. Context. contextloaderlistener </listener-class>
</Listener>
<Listener>
<Listener-class> com. Atlassian. xwork. Ext. resolversetupservletcontextlistener </listener-class>
</Listener>
<Servlet>
<Servlet-Name> webwork </servlet-Name>
<Servlet-class> com. opensymphony. webwork. Dispatcher. servletdispatcher </servlet-class>
</Servlet>
<Servlet-mapping>
<Servlet-Name> webwork </servlet-Name>
<URL-pattern> *. Action </url-pattern>
</Servlet-mapping>

<Taglib>
<Taglib-Uri> webwork </taglib-Uri>
<Taglib-location>/WEB-INF/webwork. TLD </taglib-location>
</Taglib>

</Web-app>

We have configured two listeners and a servlet. this servlet is responsible for action forwarding. For details about the working principle of action, refer to the source code of xwork.
Before the configuration, I want to briefly introduce the function that I want to implement, that is, simply insert some data into a MySQL table.
First, I used middlegen-Hibernate and hibernate-extensions (I didn't use the eclipse hibernate plug-in, and I like to use these two tools to generate) to generate the HBM corresponding to the table. XML file and two Java classes. The table field is "tablename, fieldname, chinesename", and the table name is
"Retriable", where tablename and fieldname are used as the double primary key. In this way, the generated class should be two, one primary key class and the primary class itself, I added them to my project.
Then I made an Interface Class
Package com. cz. struct;

/**
* @ Author tijichen
*
* Todo to change the template for this generated type comment go
* Window-preferences-Java-code style-code templates
*/
Public interface systabledao {
Public abstract void insert (writable data );
}
Then the implementation class
Package com. cz. struct;
Import net. SF .*;
Import org. springframework. Orm. hibernate. Support. hibernatedaosupport;
/**
* @ Author tijichen
*
* Todo to change the template for this generated type comment go
* Window-preferences-Java-code style-code templates
*/
Public class systabledaoimp extends hibernatedaosupport implements
Systabledao {
Public void insert (writable data)
{
This. gethibernatetemplate (). Save (data );
}
}
Why use interface classes? Because spring uses Java Dynamic proxy, you can refer to xiaxin's spring guide for this part.
In the insert method, I directly called the hibernate template method provided by spring, which is really convenient.

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.