1. Establishment of basic applications and environments
(Translator: This tutorial is originally used by Ant manual compilation and deployment, where there is a different place to use the Eclipse development environment, you can refer to the original text)
(1) Development environment
l Java SDK 1.4.2
l apache tomcat 5.0.25
l Eclipse 3.0
l Eclipse plugin:
Ø EMF SDK 2.0.1: ECLIPSE modeling framework, Lomboz plugin, you can use Runtime version)
Ø Lomboz 3.0: J2EE plugin for developing J2EE applications in Eclipse
Ø Spring IDE 1.0.3: Spring Bean Configuration Management Plugin
l Springframework 1.0.2
(2) Plug-in configuration
The following is a simply talking about the main configuration of the above plugin in Eclipse:
Lomboz
l Window / Customize Perspective / Shoutcuts / New: Select Java / Lomboz J2EE Wizards / Lomboz J2ee Project
l Window / Customize Perspective / Commands: Check Lomboz Actions
l Window / Preferences / Lomboz: Specify the location of JDK Tools.jar
l Window / Preferences: Select Server Types to apache tomcat v5.0.x, specify Tomcat installation directory, HTTP access address and port number (Translator: Use 8888), and ClassPath variables in Properties Tomcat_home value (ie Tomcat installation directory)
Spring IDE
l WINDOW / CUSTOMIZE PERSPECTIVE / SHOUTCUTS / SHOW View: Select Spring Ide
(3) Creating a J2EE project
l File / New / Lomboz J2EE Project
l Project settings: Specify project name SpringApp
l Java settings: Note that the default output directory is bin, change to SpringApp / SpringApp / Web-INF / CLASSES
l Create J2EE Module: Select the web modules page, click the Add button to specify the web module name SpringApp; select the Targeted Servers page, Type Select Apache Tomcat V5.0.x, click Add buttons to increase
l Click the finish button to complete the creation of the project.
(4) INDEX.JSP
Create an application's entry page INDEX.JSP, here is just a test of the environment:
this is my test. p>
body>
html>
(5) Deploy the application to Tomcat
l On the toolbar, click the Press to Open A J2EE Project Outline button, open the Lomboz J2EE VIEW view
l Select the SpringApp module of SpringApp project in the modules page, right click to select Deploy
(6) Test application
l In the browser, enter http: // localhost: 8888 / springApp, see the normal test page, indicating that the environment has been established.
l The following starts to develop Spring MVC applications
(7) Modify the web-inflicity of Web.xml
l Define DispatCherServlets to control all requests, while having a standard servlet-maping map to * .htm URL mode
servlet>
servlet-maping>
l Create SpringApp-Servlet.xml (App Program Name --Servlet.xml), configure the web application for DispatcherServlet to use Context
Ø Define the bean entry named SpringAppController, point to the SpringAppController controller
Ø Use SimpleurlHandlerMapping to define the URL mapping, map the /hello.htm to the SpringAppController controller
XML Version = "1.0" encoding = "UTF-8"?>
- Application Context Definition for "SpringApp" DispatcherServlet.
->
Return New ModelandView ("Hello.jsp"); } } (10) Creating view hello.jsp
greetings. p>
body>
html>
(11) Copy and modify Log4j.properties
l Springframework uses the log4j record log, so import Samples / PetClinic / War / Web-INF / CLASSES / LOG4J.PROPERTIES file to the SpringApp / Web-INF / CLASSES directory of SpringApp project
l Modify log4j.properties, specify the log output file:
# For jboss: Avoid to setup log4j outside $ jboss_home / server / default / deploy / log4j.xml!
# For all other servers: Comment Out the log4j listener in web.xml too.
# log4j.rootlogger = info, stdout, logfile
Log4j.appender.stdout = org.apache.log4j.consoleAppender
Log4j.Appender.stdout.Layout = Org.apache.log4j.patternlayout
Log4j.Appender.stdout.Layout.conversionPattern =% D% p [% C] - <% m>% N
Log4j.Appender.logfile = org.apache.log4j.rollingfileappender
Log4j.Appender.logfile.file = $ {Springapp.Root} /web-inf/springapp.log
Log4j.Appender.logfile.maxfilesize = 512KB
# Keep Three Backup Files.
Log4j.Appender.logfile.maxbackupindex = 3
# Pattern to output: Date Priority [category] - Message
Log4j.Appender.logfile.Layout = org.apache.log4j.patternlayout
Log4j.Appender.logfile.Layout.conversionPattern =% D% p [% C] -% M% N
L (Translator: Tips below when deploying, log4j does not work properly, looking high of high finger)
Log4j: warn no appenders could be found for logger (org.apache.catalina.session.managerbase).
Log4J: Warn Please Initialize The log4j system prot in.
(12) Re-deploy the application L Re-deploy the application via the previous method
l (Translator: Before re-deployment, you need to remove the SpringApp directory under Tomcat's WebApps directory, otherwise Tomcat will not extract the new WAR file. What is the problem?)
l Enter http: // localhost: 8888 / springApp / hello.htm, you can display the content of Hello.jsp.