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: