maven+springmvc+spring data jpa


1、 maven创建web项目

mvn archetype:create -DgroupId=com.mycompany.webapp -DartifactId=myweb -DarchetypeArtifactId=maven-archetype-webapp

maven创建多模块工程
mvn archetype:generate ^
-DarchetypeArtifactId=appdot-archetypes-archetype ^
-DarchetypeGroupId=org.appdot.archetypes ^
-DarchetypeVersion=2.0.0-RC2 ^
-DarchetypeRepository=http://repo.appdot.org/nexus/content/groups/public/ ^
-DarchetypeRepositoryId=appdot-repo -DdefaultEncoding=UTF-8

2、使用jetty发布,修改pom.xml


  4.0.0
  com.mycompany.webapp
  myweb
  war
  1.0-SNAPSHOT
  myweb Maven Webapp
  http://maven.apache.org
  
    
      junit
      junit
      3.8.1
      test
    
  
  
    myweb
    
    	
	    
		    org.mortbay.jetty
		    maven-jetty-plugin
	    
    
  

3、添加其他资源文件目录结构

src/test/java
src/test/resources
src/main/java
src/main/webapp

4、 集成 springmvc 

(1)    修改pom.xml,增加springspringmvc的依赖包


  4.0.0
  com.mycompany.webapp
  myweb
  war
  1.0-SNAPSHOT
  myweb Maven Webapp
  http://maven.apache.org
  
  
	3.2.5.RELEASE
  
	
  
  
  
  
    
      junit
      junit
      3.8.1
      test
    
    
   	
	
		org.springframework
		spring-core
		${spring.version}
	
	
		org.springframework
		spring-context
		${spring.version}
	
	
		org.springframework
		spring-jdbc
		${spring.version}
	
	
		org.springframework
		spring-beans
		${spring.version}
	
	
		org.springframework
		spring-web
		${spring.version}
	
	
		org.springframework
		spring-expression
		${spring.version}
	
	
		org.springframework
		spring-orm
		${spring.version}
	
	
		org.springframework
		spring-tx
		${spring.version}
	
	
		org.springframework
		spring-test
		${spring.version}
	
	
	
	 
         
           org.springframework  
           spring-webmvc  
           ${spring.version}  
        
         
        
  
  
  
  
    myweb
    
    	
	    
		    org.mortbay.jetty
		    maven-jetty-plugin
	    
    
  

2web.xml中增加Spring-MVC的请求转发器




  Archetype Created Web Application
  
   
  
	  spring-mvc
	  org.springframework.web.servlet.DispatcherServlet
	  
		  contextConfigLocation
		  classpath:springmvc-servlet.xml
	  
	  1
  
  
  spring-mvc
  /
  
  

3)在scr/main/resources中添加springmvc-servlet.xml






	
	
	
	
     

   
	
	

     
       
    
	  
	  
	   
     

4TestController

package com.web.test.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;


/**
 * 
 * @author xuzebin
 *
 */
@Controller
@RequestMapping("/test")
public class TestController {

	@RequestMapping("/show")
	public String show(){
		System.out.println("hello world");

		return "test";
	}

	
}

5、集成spring data jpahibernate

(1)pom.xml中增加对应的依赖包


		
			org.springframework.data
			spring-data-commons
			1.7.1.RELEASE
		
		
			org.springframework.data
			spring-data-jpa
			1.5.1.RELEASE
		
		
		
		
		
			org.hibernate
			hibernate-core
			${hibernate.version}
		
		
			org.hibernate
			hibernate-entitymanager
			${hibernate.version}
		
		
		
		
		
		
			mysql
			mysql-connector-java
			5.1.21
		
		
		
		
			com.kenai.nbpwr
			org-apache-commons-dbcp
			1.2.2-201002241055
		
		
		
		
		
			org.aspectj
			aspectjweaver
			1.7.0
		

2)修改web.xml

    
    
    org.springframework.web.context.ContextLoaderListener   
   
    
  
  contextConfigLocation
  classpath:applicationContext.xml
  

  
  
  
  	encodingFilter
  	org.springframework.web.filter.CharacterEncodingFilter
  	
    	encoding
    	UTF-8
  	
  	
    	forceEncoding
    	true
  	
  
  
  	encodingFilter
  	/*
   


    
    
      openEntityManagerInViewFilter  
      org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter  
    
    
      openEntityManagerInViewFilter  
      /*  
   

3)在src/main/resources中加入applicationContext.xml



	
	
		
	

	

	
	

	

	
		
		
		
			
		
		
			
				
				
				
				
			
		
		
			
		
		
			
				
				
				
				
				
				
				
				
			
		
	

	
	
		
	
	
	
	
		
			org.gjt.mm.mysql.Driver
		
		
			jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8
		
		
		
	

	
	

6、目录结构图

maven+springmvc+spring data jpa_第1张图片


7、源码下载

简例下载


8、补充

pom.xml中还需增加(置于中),不然重新clean   install时目录src/main/webapp会消失

  	
	
		
			src/test/resources
			true
		
		
			src/main/webapp
			true
			
				**/*.xml
			
		
	



你可能感兴趣的:(springjpa,java开发,springmvc,maven,web)