Spring 2.0 core technology and best practices Day 3

Source: Internet
Author: User

Day 3

1. ioc_xdoclet learning, used by XDoclet (three configuration files, the annotation to be written in one bean, and the jar package of XDoclet)
Configure ant (linking spring templates, you can also combine hand-written spring-bean.xml) to achieve automatic generation of XML (bin/config. XML)
Ant build. XML (Key configuration file)
<? XML version = "1.0" encoding = "UTF-8"?>
<Project name = "helloworld" default = "gen-spring-conf" basedir = ".">
<Property name = "src. dir" value = "src"/> // Bean
<Property name = "Lib. dir" value = "lib"/> // classpath
<Property name = "Conf. dir" value = "conf"/> // custom configuration file, which can be merged with automatically generated configuration files.
<Property name = "build. dir" value = "bin"/> // generated,
<Property name = "template. dir" value = "template"/> // folder using the template

<! -- Define classpath -->
<Path id = "Master-classpath">
<Fileset dir = "$ {Lib. dir}">
<Include name = "**/*. Jar"/>
</Fileset>
<Pathelement Path = "$ {build. dir}"/>
</Path>

<! -- Compile Java source code -->
<Target name = "compile">
<Mkdir dir = "$ {build. dir}"/>
<Javac destdir = "$ {build. dir}" target = "1.5" DEBUG = "on" debuglevel = "lines">
<Classpath refID = "Master-classpath"/>
<SRC Path = "$ {SRC. dir}"/>
</Javac>
</Target>

<! -- Key: Use XDoclet to generate a configuration file -->
<Target name = "gen-spring-conf" depends = "compile">
<! -- Define an ant task -->
<Taskdef name = "springdoclet"
Classname = "XDoclet. modules. Spring. springdoclettask"
Classpathref = "Master-classpath"
/>
<! -- Generate a configuration file -->
<Springdoclet
Destdir = "$ {build. dir}" // target
Mergedir = "$ {Conf. dir}" //
Force = "true"
Excludedtags = "@ version, @ author, @ todo" // unread Annotation
>
<Fileset dir = "$ {SRC. dir}" includes = "**/*. Java"/>
<Springxml
Xmlencoding = "UTF-8"
Templatefile = "$ {template. dir}/custom_spring_xml.xdt"
Destinationfile = "config. xml"
/>
</Springdoclet>
</Target>

</Project>

 
Do not automatically generate XML Syntax: (copy manually written to bin directly)
<! -- Compile Java source code -->
<Target name = "compile" depends = "init">
<Mkdir dir = "$ {build. dir}"/>
<Javac destdir = "$ {build. dir}">
<Classpath refID = "Master-classpath"/>
<SRC Path = "$ {SRC. dir}"/>
</Javac>
<! -- Copy beans. xml -->
<Copy todir = "$ {build. dir}">
<Fileset file = "$ {SRC. dir}/beans. xml"/>
</Copy>
</Target>

Hand-written configuration spring-beans.xml (this file may not be available)
<! -- Pre-defined beans -->

<Bean id = "date" class = "Java. util. Date"/>

<Bean id = "systemstarttime" class = "org. springframework. JNDI. jndiobjectfactorybean">
<Property name = "jndiname" value = "Java: COMP/ENV/systemstarttime"/>
</Bean>

Template custom_spring_xml.xdt (common and scalable)
(In spring 2.0 core technology and best practices
"CD/software/xdoclet_with_javadoc-1.5/custom_spring_xml.xdt"
Due to the length, the source code will not be posted here .)

XDoclet
Annotation in Bean:
Class
/**
* @ Spring. Bean id = "basicbean" Scope = "prototype"
*/
/**
* @ Spring. Bean ref = "basicbean"
*/
Public void setbasic (basicbean)
Attribute
/**
* @ Spring. property value = "100"
*/
/**
* @ Spring. property list = "2.32, 9.23, 10.3" strongly typed
*/
Public void setprices (list <float> prices ){
/**
* @ Spring. property list = "," Array
*/
Public void setfibonacci (INT [] Fibonacci)
/**
* @ Spring. Property SETREF = "basicbean, constructorbean, listbean"
*/
Public void setcups (set cups)

Structure
/**
* @ Spring. constructor-Arg type = "int" value = "100"
* @ Spring. constructor-Arg type = "int" value = "200"
*/

/**
* @ Spring. Bean id = "examplebean" init-method = "init"
*/
/**
* @ Spring. Property listref = "basicbean, constructorbean"
*/
Public void setchildren (list children ){}

Finally, run build. XML to automatically generate the configuration file bin/config. xml !!!
Attachment: XDoclet jar package in "CD/software/xdoclet_with_javadoc-1.5 ../lib"

2. The idea of AOP is complex
AOP is a continuation of OOP and is short for Aspect Oriented Programming, meaning cross-section programming.
Gof refers to Gang of Four, which means four-person support, the design mode name contains 23 design modes, which are compiled by Erich Gamma, Richard Helm, Ralph Johnson, and John vissides. http://baike.baidu.com/view/1082055.htm)
3.www.livebookstore.net study livebookstore and learn all the knowledge points.

How to Write pre-processing statements *. BAT and HSQLDB databases?

Live bookstore Installation Guide (Windows)
1. Install JDK 5
Live bookstore can only run on Java 5 or later Java virtual machines, and does not support JDK 1.4.x or earlier versions. Run the JDK 5.0 installation program on the CD-Rom to complete JDK 5 installation. Then, set the following environment variables:
Java_home = <JDK 5 installation directory>
Path = % java_home %/bin; <other...>

To test environment variables, open a command prompt and enter the following command:
C:/> JAVA-version
The prompt message similar to "Java version 1.5.0 _ 08" should be displayed. Otherwise, check the settings of the environment variables java_home and path.

2. Install ant (optional)
Ant is a required tool for building live bookstore. Eclipse 3.2 has built-in ant. If you need to build a project from eclipse, you need to install ant.

Decompress the ant package on the CD of this book to the local hard disk, and then set the following environment variables:
Ant_home = <ant root directory>
Path = % ant_home %/bin; % java_home %/bin; <other...>

To test environment variables, open a command prompt and enter the following command:
C:/> ant-H
Ant's help information should be displayed. Otherwise, check the settings of the environment variables ant_home and path.

3. install Resin 3.1
Resin 3.1 is the Web server used to run Live bookstore. decompress the resin 3.1 package on the CD of this book to the local disk, and then set the following environment variables:

Decompress the resin package on the CD of this book to the local hard disk, and then set the following environment variables:
Resin_home = <resin 3.1 root directory>

To test whether the Resin server can be started properly, open a command prompt and enter the following command:
C:/> % resin_home %/httpd

The control window of the Resin server should pop up. Otherwise, check the setting of the Environment Variable resin_home.
To disable the Resin server, click "quit" in the resin control window.

Resin 3.1 The default character encoding is a ISO-8859-1, if the Chinese cannot be properly displayed, please replace the/CONF/app-default.xml file under the resin root directory with the app-default.xml in the supporting disc, or manually modify the relevant part of the app-default.xml file:
Set
<Servlet-name = "Resin-file"
Servlet-class = "com. Caucho. servlets. fileservlet"/>
Changed:
<Servlet-name = "Resin-file"
Servlet-class = "com. Caucho. servlets. fileservlet">
<Init>
<Character-encoding> UTF-8 </character-encoding>
</Init>
</Servlet>

4. Start the live bookstore application
Copy the source code directory source/livebookstore in the CD-Rom of this book to the local hard disk, and then execute the following command:
Start the HSQLDB Database: db_start.bat
(Do not close the command line window of HSQLDB)
Start resin: resin_start.bat

5. Test the live bookstore application
Open your browser and enter the following in the address bar:
Http: // localhost: 8080/
Wait a moment (for the first visit, JSP compilation is required, and a little longer). the homepage of live bookstore should appear.

The built-in HSQLDB has already created two users:

Administrator user
Login Name: Admin
Password: livebookstore

Common User
Login Name: Live
Password: livebookstore

6. Miscellaneous
The root directory of the live bookstore application is as follows:

API-Doc
The complete API documentation can be regenerated using the ant command "ant apidoc"

Auto-gen
The automatically generated script for creating database tables can be regenerated using the ant command "ant make-schema"

DB
Database files of HSQLDB

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.