Maven+Spring+SpringMVC+Hibernate+Mina配置(二)

二、Spring、SpringMVC的配置

1.引入Spring、SpringMVC的jar包

在pom.xml中添加如下依赖:

 

  0.0.1-SNAPSHOT
  maven Maven Webapp
  http://maven.apache.org
  
	
	    org.springframework
	    spring-core
	    4.3.0.RELEASE
	
	
		org.springframework
		spring-webmvc
		4.3.0.RELEASE
	
	
	    javax.servlet
	    servlet-api
	    3.0-alpha-1
	
	
  
  
    maven
  

maven会帮我们下载jar包,其jar为:

 

Maven+Spring+SpringMVC+Hibernate+Mina配置(二)_第1张图片

 

2.建立包结构、配置文件

  Maven+Spring+SpringMVC+Hibernate+Mina配置(二)_第2张图片

    配置web.xml

 



	maven
	
		contextConfigLocation
		classpath:spring.xml
	
	
		字符集过滤器
		encodingFilter
		org.springframework.web.filter.CharacterEncodingFilter
		
			字符集编码
			encoding
			UTF-8
		
	
	
		encodingFilter
		/*
	
		
	
		spring监听器
		org.springframework.web.context.ContextLoaderListener
	
	
		org.springframework.web.util.IntrospectorCleanupListener
	

	
		spring mvc servlet
		springmvc
		org.springframework.web.servlet.DispatcherServlet
		
			spring mvc 配置文件
			contextConfigLocation
			classpath:spring-mvc.xml
		
		1
	
	
	
		springmvc
		*.do
	
	
		index.jsp
		

 

 

 

  在spring.xml文件中 ,配置需要扫描的包

 

	
	

 

 

 

 在spring-mvc.xml文件中,配置:

 

	
	

	
	


写几个测试类

 

 

 

package best.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import best.service.TestSerivceI;
import best.service.impl.TestServiceImpl;

@Controller
@RequestMapping("/testController")
public class TestController extends BaseController{

	private  TestSerivceI testService;
	
	@Resource
	public void setTestService(TestSerivceI testService) {
		this.testService = testService;
	}	

	@RequestMapping("/login")
	public String login(HttpServletRequest request) {

		return "login";
	}
}

 

 

此处login是转到WEB-INF下的view下的login.jsp ,另外使用的是8090端口,浏览器地址输入http://localhost:8090/maven/testController/login.do

Maven+Spring+SpringMVC+Hibernate+Mina配置(二)_第3张图片



 

你可能感兴趣的:(JavaWeb)