Learn Java from scratch-Build the Spring MVC Framework __java Learning Route

Source: Internet
Author: User
Tags aop java web
Nothing is more sentimental than the decline of an era .

The whole society and people are in the pursuit of innovation, progress, growth, no one is willing to stop before, the old things slowly from our lives disappear really is so sad mody. or be replaced. I think some of them are, but some things are not.

Lantian and Blue Jade are not explaining the two distinct lives. With the progress of society, those disappearing art or folk arts may be in reality we can no longer see, this society is always the fittest, disappear to think that no longer need, but these old objects have more technical and spiritual aspects of things.

I've only recently seen the movie on the internet, birds pay homage. After watching me for a long time can not move, it does not have a strong drama conflict, the picture is not delicate, the characters are not prominent, but it speaks the suona this thing, not brain remnants, is moving, this is the film thinking. If you create a Spring project

The spring MVC framework should be unknown to Java WEB projects, and you will not build a spring framework. As a just learning Java I will, if you do not, that can be really sad.

1. After you create a project in MyEclipse, you can configure a Spring project in the chosen way, which is not discussed here. Because I only use Eclipse.

2. Build manually. Just do it. Create a new Java Web project

1. Open Eclipse, right-click under the Project Explorer tab and choose Web-dynamic Web prodect (This step should know ...) )。

2. Click Next. Start a project that you think is a good name, note: Naming is important, every time as a name for their children as solemn and sacred.

3. No, it's done.

get a jar package for the Spring framework

Whether you're using cheat or sipilailian, you can just get the Spring frame jar package. I give you an address here, you can be decent to download on the line. Address: http://projects.spring.io/spring-framework/
Find a suitable version, download down to save to the right location on it, it is so simple. After decompression, this should be the case:

If you look at the name of the package, you probably understand what the jar bag is all about, and the next step is to introduce what you need.
Then, you want the jar package you need, copy it to the project's/webcontent/web-inf/lib, why do it, the following will be said. Import jar Packs

Remember when a friend of Java learning complained: "Java every day in the guide bag, not as. Net cool." I don't think so now.
On the project name, click the right button, build path-configure Bulid Path ...-libraries-add JARs ..., find the item's/webcontent/web-inf/lib in the pop-up box, So you can see the jar bag that you just copied over.

Configure configuration configuration

The most important step in setting up the Spring framework should be configuration. The official website explains the framework as follows:

The Spring MVC Framework is designed around a dispatcherservlet that distributes requests to individual processors, supports configurable processor mappings, view rendering, localization, time zone and theme rendering, and even supports file uploads. Processors are classes and methods that annotate @Controller and @RequestMapping in your application, and Spring provides a very versatile and flexible configuration for the processor approach.

So, first we should create a new Web.xml file under/webcontent/web-inf/, and then configure Dispatcherservlet in this file.

<servlet>
    <servlet-name>springMVC</servlet-name>
    <servlet-class> Org.springframework.web.servlet.dispatcherservlet</servlet-class>
    <load-on-startup>1</ load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>springmvc</ servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
< context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/ Web-inf/applicationcontext.xml</param-value>
</context-param>

The

can also configure character encoding, default startup page, or something, which is not configured here, as shown in the example project: https://github.com/mafly/SpringDemo/blob/master/WebContent/WEB-INF/ Web.xml, because this is dispatcherservlet named Springmvc, and it is loaded as soon as the Web project starts. Next we need to create a springmvc-servlet.xml spring configuration file in the/webcontent/web-inf/directory. The default file name recommended on the spring Official document is [Servlet-name]-servlet.xml file, where Servlet-name is called SPRINGMVC, so I created a new springmvc-servlet.xml.

<?xml version= "1.0" encoding= "UTF-8"?> <beans "xmlns=" xmlns: Xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:p= "http://www.springframework.org/schema/p" Xmlns:cont ext= "Http://www.springframework.org/schema/context" xmlns:util= "Http://www.springframework.org/schema/util" Xmlns:mvc= "Http://www.springframework.org/schema/mvc" xsi:schemalocation= "Http://www.springframework.org/schema /beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/ Util http://www.springframework.org/schema/util/spring-util-4.2.xsd http://www.springframework.org/schema/ Context Http://www.springframework.org/schema/context/spring-context-4.2.xsd http://www.springframework.org/ Schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd "> <!--Use the default annotation mapping--> &LT;MVC: Annotation-driven/> <mvc:resources location= "/" mapping= "/index.html"/> <!--Automatically scans the controllers in the controller package--> <context:component-scan base-package= "Cn.mayongfa.api.controller"/> <context: Component-scan base-package= "Cn.mayongfa.controller"/> <!--upload file intercept, set maximum upload file size 30m=30*1024*1024 (B) =31457280 Bytes--> <bean id= "Multipartresolver" class= " Org.springframework.web.multipart.commons.CommonsMultipartResolver "> <property name=" maxuploadsize "value=" 31457280 "/> </bean>

Specific details: https://github.com/mafly/SpringDemo/blob/master/WebContent/WEB-INF/springMVC-servlet.xml
We define the contextconfiglocation in the Web.xml file, specify the Spring configuration file to be loaded, and the generic file is named Applicationcontext.xml, in which we can scan the class package, read the configuration file, Data source management, AOP configuration, caching, and Message Queuing configurations, so the next step is to create a new Applicationcontext.xml file.

<?xml version= "1.0" encoding= "UTF-8"?> <beans "xmlns=" xmlns: Xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:p= "http://www.springframework.org/schema/p" xmlns:context= "Http://www.springframework.org/schema/context" xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" 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/AOP http:// Www.springframework.org/schema/aop/spring-aop.xsd "> <!--read multiple profiles into the container and give spring management--> <bean id="
  Propertyconfigurer "class=" Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer ">  <property name= "Locations" > <list> <value>classpath:global.properties</value&gt
            ; <value>classpath:jdbc.properties</value> </list> </property> </bean> <!--scan Class package that automatically converts the class that is annotated with the spring annotation to the bean, while completing the bean injection--> <context:component-scan base-package= "Cn.mayongfa.common"/> < Context:component-scan base-package= "Cn.mayongfa.service"/> <context:component-scan base-package= " Cn.mayongfa.dao "/> <!--master configuration data source--> <bean id=" Masterdatasource "class=" Com.alibaba.druid.pool.DruidDataSource "init-method=" Init "destroy-method=" close "> <property name=" Drivercla Ssname "> <value>${master.jdbc.driverClassName}</value> </property> <property name= 
        "url" > <value>${master.jdbc.url}</value> </property> <property name= "username" > <value>${master.jdbc.username}</value>;/property> <property name= "password" > <value>${master.jdbc.password}</value> </pr Operty> ... </
Related Article

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.