Springmvc Getting Started (iii) +spring application (integration)

Source: Internet
Author: User

let's review it before we integrate. Spring and the Spring MVC

Spring :

The core of the spring framework is the provision of a container that can manage bean components, such as creating bean objects, destroying a bean object, and so on. In addition, the container has IOC and AOP advanced features to decouple bean object calls.

Springmvc :

Spring MVC is an MVC open-source framework similar to struts, in fact all belong to spring,spring MVC needs to have spring's Jar package as a support to run.

Spring and the Spring MVC consolidation no longer requires a copy Jar package, because Spring of the Jar The package is also used to Springmvc the

configuration file Web. XML

<!--Modify Spring's profile path and name--<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:config/springAnnotation-core.xml</param-value> </context-param> <!- -Configure spring--> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener< /listener-class> </listener> <!--SPRINGMVC configuration--<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*: Config/springannotation-servlet.xml</param-value> </init-param> <load-on-startup>1</  Load-on-startup> </servlet><servlet-mapping> <servlet-name>springMVC</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>


The following examples illustrate:

One interface: ispring  

Public interface Ispring {public String get ();}

An implementation class: Springmanager


public class Springmanager implements ispring {@Overridepublic String get () {System.out.println ("------I AM Springmanager----"); return" I am GetMethod ";}}

in the Spring the configuration file ( Springannotation-core.xml ) to add the configuration ( Spring not using annotations)

<beans><bean id= "Springmanager" class= "Com.tgb.web.controller.annotation.SpringManager" ></bean ></beans>


Spring MVC configuration file ( Springannotation-servlet.xml ):

<!--note Scanning package--><context:component-scan base-package= "Com.tgb.web.controller.annotation"/><!--opening annotations, Both of these methods are universal--><!--<bean class= " Org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter "/><bean class=" Org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping "></bean> <mvc: Annotation-driven></mvc:annotation-driven><bean id= "Viewresolver" class= " Org.springframework.web.servlet.view.InternalResourceViewResolver "><property name=" prefix "value="/"> </property><property name= "suffix" value= ". JSP" ></property></bean>


so Controller How do I get to the interface method?


@Controllerpublic class Springcontroller {/*name corresponds to the value of the bean's ID value in the Spring configuration file */@Resource (name= "Springmanager") private Ispring Springmanager; @RequestMapping ("/spring/get") public String Get () {System.out.println (Springmanager.get ()); return "/success";}}

success.jsp

<body>spring Integration Success!!! </body>

Display effect:

Visit: Http://localhost:8080/springMVC9/spring/get



Summarize:

Spring with the Springmvc The purpose of integration is also to play their respective advantages, it is important that we do not mistakenly believe that Spring and the Spring MVC is the same, Spring manage the creation of objects for containers, etc., Springmvc Is a front-end MVC Framework.




Springmvc Getting Started (iii) +spring application (integration)

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.