github上有一个Mybatis-Spring的项目,专门用于辅助完成mybatis与spring的整合,大大简化了整合难度,使用步骤:
准备工作:
maven依赖项:
1 <properties> 2 <java-version>1.6</java-version> 3 <spring.version>3.2.8.RELEASE</spring.version> 4 </properties> 5 <dependencies> 6 7 <!-- Spring --> 8 <dependency> 9 <groupId>org.springframework</groupId> 10 <artifactId>spring-core</artifactId> 11 <version>${spring.version}</version> 12 </dependency> 13 14 <dependency> 15 <groupId>org.springframework</groupId> 16 <artifactId>spring-expression</artifactId> 17 <version>${spring.version}</version> 18 </dependency> 19 20 <dependency> 21 <groupId>org.springframework</groupId> 22 <artifactId>spring-beans</artifactId> 23 <version>${spring.version}</version> 24 </dependency> 25 26 <dependency> 27 <groupId>org.springframework</groupId> 28 <artifactId>spring-context</artifactId> 29 <version>${spring.version}</version> 30 </dependency> 31 <dependency> 32 <groupId>org.springframework</groupId> 33 <artifactId>spring-context-support</artifactId> 34 <version>${spring.version}</version> 35 </dependency> 36 <dependency> 37 <groupId>org.springframework</groupId> 38 <artifactId>spring-web</artifactId> 39 <version>${spring.version}</version> 40 </dependency> 41 42 <dependency> 43 <groupId>org.springframework</groupId> 44 <artifactId>spring-webmvc</artifactId> 45 <version>${spring.version}</version> 46 </dependency> 47 48 <dependency> 49 <groupId>org.springframework</groupId> 50 <artifactId>spring-oxm</artifactId> 51 <version>${spring.version}</version> 52 </dependency> 53 54 <dependency> 55 <groupId>org.springframework</groupId> 56 <artifactId>spring-jdbc</artifactId> 57 <version>${spring.version}</version> 58 </dependency> 59 60 <dependency> 61 <groupId>org.springframework</groupId> 62 <artifactId>spring-tx</artifactId> 63 <version>${spring.version}</version> 64 </dependency> 65 66 <dependency> 67 <groupId>org.springframework</groupId> 68 <artifactId>spring-aop</artifactId> 69 <version>${spring.version}</version> 70 </dependency> 71 72 73 <dependency> 74 <groupId>org.aspectj</groupId> 75 <artifactId>aspectjweaver</artifactId> 76 <version>1.7.3</version> 77 </dependency> 78 79 <dependency> 80 <groupId>aopalliance</groupId> 81 <artifactId>aopalliance</artifactId> 82 <version>1.0</version> 83 </dependency> 84 85 <!-- json --> 86 <dependency> 87 <groupId>org.codehaus.jackson</groupId> 88 <artifactId>jackson-mapper-asl</artifactId> 89 <version>1.9.3</version> 90 </dependency> 91 92 <dependency> 93 <groupId>org.codehaus.jackson</groupId> 94 <artifactId>jackson-jaxrs</artifactId> 95 <version>1.9.9-redhat-2</version> 96 </dependency> 97 98 <!-- logback --> 99 <dependency> 100 <groupId>org.slf4j</groupId> 101 <artifactId>slf4j-api</artifactId> 102 <version>1.7.7</version> 103 </dependency> 104 105 <dependency> 106 <groupId>ch.qos.logback</groupId> 107 <artifactId>logback-core</artifactId> 108 <version>1.1.2</version> 109 </dependency> 110 111 <dependency> 112 <groupId>ch.qos.logback</groupId> 113 <artifactId>logback-classic</artifactId> 114 <version>1.1.2</version> 115 </dependency> 116 117 <dependency> 118 <groupId>commons-logging</groupId> 119 <artifactId>commons-logging</artifactId> 120 <version>1.1.3</version> 121 </dependency> 122 123 <!-- Servlet --> 124 <dependency> 125 <groupId>javax.servlet</groupId> 126 <artifactId>servlet-api</artifactId> 127 <version>2.5</version> 128 <scope>provided</scope> 129 </dependency> 130 131 <!-- oracle --> 132 <dependency> 133 <groupId>com.oracle</groupId> 134 <artifactId>ojdbc6</artifactId> 135 <version>11.2.0.3</version> 136 </dependency> 137 138 <!-- mybatis --> 139 <dependency> 140 <groupId>org.mybatis</groupId> 141 <artifactId>mybatis-spring</artifactId> 142 <version>1.2.2</version> 143 </dependency> 144 145 <dependency> 146 <groupId>org.mybatis</groupId> 147 <artifactId>mybatis</artifactId> 148 <version>3.2.7</version> 149 </dependency> 150 151 152 </dependencies>