Today suddenly want to make a website, intends to use SPRINGMVC (4.1.5.RELEASE) +hibernate (4.3.8.Final) as the main frame, to try the effect.
Put out some of Maven's code first:
<properties ><spring-version>4.1.5.release</spring-version>Then I'll start at the beginning and say how I've been doing all the work.
First of all, of course, open Eclipse, build a MAVEN project, choose the corresponding WebApp maven template, completed after an empty Maven project came out.
I this eclipse built out of the directory is not complete, do not know whether this is the case, I say my solution, first go to view project right->properties->java Build path->source tab, There is a map of the current directory, there are folders display miss, I use Windows to the miss of those directories are created.
Directory structure:
--src/main/java
--src/main/resources
--src/test/java
--src/test/resources
After the catalog is finished and see the project catalog at the top there is a 2.3 display, this is the version of the Dynamic Web module, Project right-->project facets here to show the version of the head, but it seems to change. After I Baidu a check, the opinion that the Netizen gives is modifies the configuration file, the configuration file is in the project root directory in the. Setting folder, the file is named Org.eclipse.wst.common.project.facet.core.xml. Change 2.3 to 3.1, restart Eclipse, and change the configuration of the Web. xml file
<?xml version= "1.0" encoding= "UTF-8"? ><web-app version= "3.1" xmlns= "Http://xmlns.jcp.org/xml/ns/javaee" Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation= "Http://xmlns.jcp.org/xml/ns/javaee/ Web-app>
, this is primarily a modification of the file version of the namespace. Of course, my 2.3 change 3.1 is completely self-toss, want to try new, also can not change.
Now that it's all set up and it's time to use the framework, I'm going to put spring mvc in. Put the following code into the Web. xml file First
<!--Spring MVC Servlet--><servlet><servlet-name>springmvc</servlet-name>< servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class><init-param>< param-name>contextconfiglocation</param-name><param-value>classpath:springmvc-config.xml</ param-value></init-param><load-on-startup>1</load-on-startup></servlet>< servlet-mapping><servlet-name>springmvc</servlet-name><url-pattern>/main/*</ Url-pattern></servlet-mapping>
This puts Springmvc's dispatcherservlet in the configuration. There is a springmvc-config.xml file, which is the configuration file for Springmvc, and the file contents are as follows:
<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "http://www.springframework.org/ Schema/beans "xmlns:mvc=" Http://www.springframework.org/schema/mvc " xmlns:xsi=" http://www.w3.org/2001/ Xmlschema-instance "xmlns:context=" Http://www.springframework.org/schema/context " xmlns:tx="/HTTP/ Www.springframework.org/schema/tx "xsi:schemalocation=" http:// www.springframework.org/schema/beans http:// www.springframework.org/schema/beans/spring-beans.xsd http:// www.springframework.org/schema/context http:// www.springframework.org/schema/context/spring-context.xsd http:// www.springframework.org/schema/tx http:// www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/mvc http:// Www.springframework.org/schema/mvc/spring-mvc.xsd "><context:component-scan base-package=" Cn.com.myweb " /><mvc:annotation-driven enable-matrix-variables=" true " /></beans>
Here I would like to say, I intend to make the configuration can be made into annotations, the main point is to see what the comments will be a problem, if you do not want to use annotations, you can find other places of configuration.
The next step is to build the class file:
@Controllerpublic class usercontroller{@RequestMapping (value = "/login", method = requestmethod.get) public String Logi N () {System.out.println ("hello,world!"); return "/index.jsp"; }}
After the configuration, publish try, look for feeling.
This part is relatively simple, first write so much, follow-up write integration hibernate part. There are questions can leave a message to me, because I have been integrated, this is the side of the code to read the summary of writing.
This article is from the "morning sky Full of Skies" blog, please be sure to keep this source http://hmdebk.blog.51cto.com/5081287/1614988
Initial integration of Spring MVC + hibernate