This time from scratch to build a Web project, found that the Web for Spring 3.0 is not much to explain, so take this opportunity to record the configuration of a basic Web project, mainly configuration spring3 process, in fact, most and 2 is similar.
Step one: Build and deploy a Web project (can skip)
1. Here to say a simple word about web projects, in fact, a Wen engineering the most basic, only see 3 places:
In the root directory (this directory is generally used to call Webcontext or Webroot) has
1. webroot/web-inf/web.xml Boot boot file
2.webroot/web-inf/classes/compiled class file, sub-paths are created based on the package
3.webroot/web-inf/lib/jar Bag (note that it is not possible to build subdirectories under Lib)
This is the commonly used Web engineering structure. With these three constructs, and then the absolute path of the Webroot to the Web container such as Tomcat, it can be started (of course, there is a corresponding thing to do).
So while the structure of our general project is: PROJECTNAME/SRC, projectname/webroot but actually src. Java source code is tomcat does not care, its parsing is from the beginning of the WebRoot,. Class is what it knows. .
The following is an initial web. Xml. This file is equivalent to the startup boot file of the project, which is first found in the website and then interpreted and started by the class.
[XHTML] View Plain Copy <?xml version= "1.0" encoding= "UTF-8"?> <web-app xmlns= " Http://java.sun.com/xml/ns/javaee " xmlns:xsi=" Http://www.w3.org/2001/XMLSchema-instance " xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee /web-app_2_5.xsd " version=" 2.5 "> <servlet> <servlet-name>TestServlet</servlet-name> <display-name> Test with servlet</display-name> <servlet-class> Test. testservlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>TestServlet</servlet-name> < url-pattern>/test/*</url-pattern> </servlet-mapping> &nBsp <welcome-file-list> <welcome-file>index.jsp</ welcome-file> </welcome-file-list> </web-app>
2. Deploy to Tomcat:
There are many ways to deploy Tomcat, and the way I prefer to deploy it is to put the Projectname.xml configuration file under apache-tomcat/conf/catalina/localhost/,
Content is
[XHTML] view plain copy <context path= "ProjectName" reloadable= "true" docbase= "d:/workspace/projectname/ WebContent "></Context>
The project was deployed. It's simple.
And then, in Eclipse, you don't have to go with the server, run the environment. To install a Tomcat plugin, specify the tomcat path. The above XML file can also be automatically generated by configuring the Eclipse-tomcat plugin.
Step two: Bring in spring jar package, this is not nonsense oh. See spring3.0 know, Spring3 the previous a Magnum Spring.jar split into 20 small jar. Of course, you can also save 20 directly to the introduction of all, no problem.
But if you don't want to do this, here's a simple jar package for the most basic dependency injection in the Web:
Org.springframework.asm-3.0.5.release.jar
Org.springframework.beans-3.0.5.release.jar
Org.springframework.context-3.0.5.release.jar
Org.springframework.core-3.0.5.release.jar
Org.springframework.expression-3.0.5.release.jar
Org.springframework.web-3.0.5.release.jar
Commons-logging-1.1.1.jar
Where Commons-logging-1.1.1.jar is spring's dependency package.
The above is a collection without SPRING-JDBC database management, if you want to use spring's persistence layer, you also need:
Org.springframework.jdbc-3.0.5.release.jar
Org.springframework.transaction-3.0.5.release.jar
Commons-dbcp-1.3.jar
Commons.pool-1.5.3.jar
Similarly, the following 2 are also spring dependent packages.
The configuration for spring persistence layer is described in the next section
Step three: To configure spring, the basic and spring2 are the same.
1 join in Web. XML
[XHTML] View plain copy <c ontext-param>