Spring and springMVC integrated Annotation Version helloworld

Source: Internet
Author: User

Spring and springMVC integrated Annotation Version helloworld

Before integration, You need to download the complete jar package of spring from the official website. I downloaded the spring-framework-3.2.2.RELEASE. Integration steps are as follows: 1. Create a new web project in eclipse, and load the downloaded spring jar package into the lib directory, but spring depends on a jar package of a commons-logging-1.1.jar at startup, you need additional downloads. 2. Write web. xml and configure the spring distributor and spring configuration file location. The details are as follows:

          
   
    spring_springMVC_IntegrationDemo
           
   
    org.springframework.web.servlet.DispatcherServlet
           
               
    
     contextConfigLocation
                
    
     classpath:config/spring.xml
            
       
      
          
   
    spring_springMVC_IntegrationDemo
           
   
    /
       
  

3. Create a config package name under src, and then create a spring. xml file. The details are as follows:


  
   
         
    
   
  

4. Create a class named UserAction. The specific content is as follows:

package com.evan.action;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import com.evan.service.IUserService;@Controller@RequestMapping(/user)public class UserAction {    @Autowired    IUserService userService;    @RequestMapping(/add)    public String addUser() {        System.out.println(userService.addUser());        return addUserView;    }}

5. Create an IUserService interface. The interface content is as follows:

package com.evan.service;public interface IUserService {    public int addUser();}

6. Create a UserServiceImpl class name. The specific content is as follows:

Package com. evan. service. impl; import org. springframework. stereotype. service; import com. evan. service. IUserService; @ Servicepublic class UserServiceImpl implements IUserService {@ Override public int addUser () {System. out. println (successfully added); return 1 ;}}

7. Create addUserView. jsp in the webContent directory with the following message:
Spring and springMVC integration successful !!

8. Add the project to the tomcat running directory. Access to www.bkjia.com can be accessed normally, indicating that the integration is successful.
9. The source code directory structure of the entire project is as follows:

 

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.