解决Maven整合SSM遇到的一系列坑

写在前面:以前没有使用maven,开发效率不太高。最近开始使用maven,于是整合ssm是不可缺的。在尝试了2个下午的整合后,今天终于成功了。整合思路都是一样的,主要是用了maven后出现了许多配置错误:

  1. jdk和maven,Dynamic Web Module不匹配
  2. pom.xml因为中英文原因等报红线:expected START_TAG or END_TAG not TEXT
  3. 报:Could not resolve resource location pattern [classpath:org/test/mapping/*.xml
  4. jar之间版本问题
  5. org.mybatis.spring.transaction.SpringManagedTransaction.getTimeout() mybatis和spring-mybatis版本问题

 

由衷希望大家能从头到尾理解好再配置,有时候遇到坑也是很好的,能加深对整合的理解。尤其是jar版本之间不匹配,这需要大家查阅官网一次次配置。一次搭建,永久使用!!!

一.jdk和maven,Dynamic Web Module不匹配

如果maven项目中java Resources报红叉,但是里面的文件却没有红叉,那么就是配置问题,而且极有可能是jdk版本和maven Dynamic Web Module不匹配。因为maven默认jdk是1.5的,所有我们需要如下配置。

  • 右击项目buildpath改变jdk版本

  • java compiler改变版本

  • project facets 改变版本

 

  • 终极大法:pom.xml添加如下配置
    <build>
    <plugins>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
    <source>1.8</source>
    <target>1.8</target>
     </configuration>
    </plugin>
    </plugins>
    </build>

     

二.pom.xml因为中英文原因等报红线:expected START_TAG or END_TAG not TEXT

在pom.xml中部分内容格式不正确,整理格式,删除多余空格。

 

三.Could not resolve resource location pattern [classpath:org/test/mapping/*.xml

在配置文件中改为classpath*:xxxxxx例如下图

 

四.jar之间版本问题

直接附上pom.xml代码。


   <properties>    
        <srping.version>4.3.12.RELEASE</srping.version>    
        <mybatis.version>3.3.1</mybatis.version>    
        <slf4j.version>1.7.12</slf4j.version>    
        <log4j.version>1.2.17</log4j.version>    
    </properties>    
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
        <scope>provided</scope>
    </dependency>
    
     <!-- java ee包 -->    
        <dependency>    
            <groupId>javax</groupId>    
            <artifactId>javaee-api</artifactId>    
            <version>7.0</version> 
            <scope>provided</scope>   
        </dependency>    
        <!-- spring框架包 start -->    
        <dependency>    
            <groupId>org.springframework</groupId>    
            <artifactId>spring-test</artifactId>    
            <version>${srping.version}</version>    
        </dependency>    
        <dependency>    
            <groupId>org.springframework</groupId>    
            <artifactId>spring-core</artifactId>    
            <version>${srping.version}</version>    
        </dependency>    
        <dependency>    
            <groupId>org.springframework</groupId>    
            <artifactId>spring-oxm</artifactId>    
            <version>${srping.version}</version>    
        </dependency>    
        <dependency>    
            <groupId>org.springframework</groupId>    
            <artifactId>spring-tx</artifactId>    
            <version>${srping.version}</version>    
        </dependency>    
        <dependency>    
            <groupId>org.springframework</groupId>    
            <artifactId>spring-jdbc</artifactId>    
            <version>${srping.version}</version>    
        </dependency>    
        <dependency>    
            <groupId>org.springframework</groupId>    
            <artifactId>spring-aop</artifactId>    
            <version>${srping.version}</version>    
        </dependency>    
        <dependency>    
            <groupId>org.springframework</groupId>    
            <artifactId>spring-context</artifactId>    
            <version>${srping.version}</version>    
        </dependency>    
        <dependency>    
            <groupId>org.springframework</groupId>    
            <artifactId>spring-context-support</artifactId>    
            <version>${srping.version}</version>    
        </dependency>    
        <dependency>    
            <groupId>org.springframework</groupId>    
            <artifactId>spring-expression</artifactId>    
            <version>${srping.version}</version>    
        </dependency>    
        <dependency>    
            <groupId>org.springframework</groupId>    
            <artifactId>spring-orm</artifactId>    
            <version>${srping.version}</version>    
        </dependency>    
        <dependency>    
            <groupId>org.springframework</groupId>    
            <artifactId>spring-web</artifactId>    
            <version>${srping.version}</version>    
        </dependency>    
        <dependency>    
            <groupId>org.springframework</groupId>    
            <artifactId>spring-webmvc</artifactId>    
            <version>${srping.version}</version>    
        </dependency>    
        <!-- spring框架包 end -->    
        <!-- mybatis框架包 start -->    
        <dependency>    
            <groupId>org.mybatis</groupId>    
            <artifactId>mybatis</artifactId>    
            <version>${mybatis.version}</version>    
        </dependency>    
        <dependency>    
            <groupId>org.mybatis</groupId>    
            <artifactId>mybatis-spring</artifactId>    
            <version>1.1.1</version>    
        </dependency>    
        <!-- mybatis框架包 end -->    
        <!-- 数据库驱动 -->    
        <dependency>    
            <groupId>mysql</groupId>    
            <artifactId>mysql-connector-java</artifactId>    
            <version>5.1.35</version>    
        </dependency>    
        <!-- 导入dbcp的jar包,用来在applicationContext.xml中配置数据库 -->    
        <dependency>    
            <groupId>commons-dbcp</groupId>    
            <artifactId>commons-dbcp</artifactId>    
            <version>1.4</version>    
        </dependency>    
        <!-- jstl标签类 -->    
        <dependency>    
            <groupId>jstl</groupId>    
            <artifactId>jstl</artifactId>    
            <version>1.2</version>    
        </dependency>    
        <!-- log start -->    
        <dependency>    
            <groupId>log4j</groupId>    
            <artifactId>log4j</artifactId>    
            <version>${log4j.version}</version>    
        </dependency>    
        <dependency>    
            <groupId>org.slf4j</groupId>    
            <artifactId>slf4j-api</artifactId>    
            <version>${slf4j.version}</version>    
        </dependency>    
        <dependency>    
            <groupId>org.slf4j</groupId>    
            <artifactId>slf4j-log4j12</artifactId>    
            <version>${slf4j.version}</version>    
        </dependency>    
        <!-- log END -->    
        <!-- Json  -->    
        <!-- 格式化对象,方便输出日志 -->    
        <dependency>    
            <groupId>com.alibaba</groupId>    
            <artifactId>fastjson</artifactId>    
            <version>1.2.6</version>    
        </dependency>    
        <dependency>    
            <groupId>org.codehaus.jackson</groupId>    
            <artifactId>jackson-mapper-asl</artifactId>    
            <version>1.9.13</version>    
        </dependency>    
        <!-- 上传组件包 start -->    
        <dependency>    
            <groupId>commons-fileupload</groupId>    
            <artifactId>commons-fileupload</artifactId>    
            <version>1.3.1</version>    
        </dependency>    
        <dependency>    
            <groupId>commons-io</groupId>    
            <artifactId>commons-io</artifactId>    
            <version>2.4</version>    
        </dependency>    
        <dependency>    
            <groupId>commons-codec</groupId>    
            <artifactId>commons-codec</artifactId>    
            <version>1.10</version>    
        </dependency> 
          
   
        <!-- 上传组件包 end -->    
  </dependencies>
  

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
 </configuration>
</plugin>


			<plugin>
				<groupId>org.codehaus.cargo</groupId>
				<artifactId>cargo-maven2-plugin</artifactId>
				<version>1.4.9</version>
				<configuration>
					<container>
						<containerId>tomcat8x</containerId>
						<home>E:\ecl\tomocat\apache-tomcat-8.5.38</home>
					</container>
					<configuration>
						<type>existing</type>
						<home>E:\ecl\tomocat\apache-tomcat-8.5.38</home>
						<!-- 默认值8080 -->
						<properties>
							<cargo.servlet.port>8888</cargo.servlet.port>
						</properties>
					</configuration>
				</configuration>
				<executions>  
					<execution>  
						<id>cargo-run</id>  
						<phase>install</phase>  
						<goals>  
							<goal>run</goal>  
						</goals>  
					</execution>  
				</executions>
			</plugin>
		</plugins>
		

		
		
		
		
	</build>
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  

五.org.mybatis.spring.transaction.SpringManagedTransaction.getTimeout() mybatis和spring-mybatis版本问题

进多次测试,发现spring 4.3.12.RELEASE 和 mybatis3.3.1和mybatis-spring1.1.1能正常使用。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值