Trackback: http://quqtalk.javaeye.com/blog/362163
Jpetstore in spring samples is based on ibatis jpetstore, and ibatis is used at the database layer. On the web layer, two MVC options are available: Spring MVC and Struts MVC (1.1 ).
Test environment:
JDK version: 1.5.0 _ 12-b04
Tomcat version: 6.0.18
Spring version: 2.5.6
MySQL version: 5.1.32
(1) go to the spring website to obtain the installation media for the jpetstore example. Go to download center at http://www.springsource.org/and select 2.5.6-with-dependencies to download.
(2) decompress the downloaded zip package. The jpetstore example is in the \ spring-framework-2.5.6 \ samples \ jpetstore directory.
(3) create a jpetstore database table in the MySQL database and import some initial data. The SQL statement for table creation and data import is in the \ spring-framework-2.5.6 \ samples \ jpetstore \ dB \ mysql directory. Run the following command to create a table and import data,
SQL code
- Mysql-H 127.0.0.1-u root-P
- Create Database jpetstore;
- Use jpetstore;
- Source \ spring-framework-2.5.6 \ samples \ jpetstore \ dB \ mysql \ jpetstore-mysql-schema. SQL
- Source \ spring-framework-2.5.6 \ samples \ jpetstore \ dB \ mysql \ jpetstore-mysql-dataload. SQL
mysql -h 127.0.0.1 -u root -p CREATE DATABASE jpetstore;USE jpetstore;source \spring-framework-2.5.6\samples\jpetstore\db\mysql\jpetstore-mysql-schema.sqlsource \spring-framework-2.5.6\samples\jpetstore\db\mysql\jpetstore-mysql-dataload.sql
(3) modify the database configuration file, \ spring-framework-2.5.6 \ samples \ jpetstore \ war \ WEB-INF directory, modify JDBC. properties,
Properties code
- JDBC. driverclassname = com. MySQL. JDBC. Driver
- JDBC. url = JDBC: mysql: // 127.0.0.1: 3306/jpetstore?
- JDBC. Username = root
- JDBC. Password =
jdbc.driverClassName=com.mysql.jdbc.Driverjdbc.url=jdbc:mysql://127.0.0.1:3306/jpetstore?jdbc.username=rootjdbc.password=
(4) In the \ spring-framework-2.5.6 \ samples \ jpetstore \ war \ WEB-INF Directory web. XML,
XML Code
- <Servlet-mapping>
- <Servlet-Name>PetStore</Servlet-Name>
- <! --
- <Servlet-Name> action </servlet-Name>
- -->
- <URL-pattern>*. Do</Url-pattern>
- </Servlet-mapping>
<servlet-mapping><servlet-name>petstore</servlet-name><!--<servlet-name>action</servlet-name>--><url-pattern>*.do</url-pattern></servlet-mapping>
Use spring or struts for MVC. PetStore indicates spring and action indicates struts.
(5) After the configuration file is modified, run the warfile command in the \ spring-framework-2.5.6 \ samples \ jpetstore directory. bat, jpetstore is created in the DIST directory. war package. Copy the war package to the webapps directory of Tomcat.
(6) start Tomcat and enter http: // 127.0.0.1: 8080/jpetstore in the browser to view the jpetstore homepage.