今天算是什么也没干,熟悉了搭建SSM框架,之前一直没有自己搭建过,所以导致博主踩了很多坑,纪念一下。不说废话了,进入正题吧。
当你搜到这篇博客时,就代表你已经知道了SSM是什么,它们整合的思路是什么,这些我就不说了,直接开始。以下是博主亲测,不会有问题,除非你那里搭错了
POM文件
1  | <?xml version="1.0" encoding="UTF-8"?>  | 
SqlMapConfig.xml
1  | <?xml version="1.0" encoding="UTF-8" ?>  | 
applicationContext-dao.xml
1  | <?xml version="1.0" encoding="UTF-8"?>  | 
applicationContext-service.xml
1  | <?xml version="1.0" encoding="UTF-8"?>  | 
applicationContext-trans.xml
1  | <?xml version="1.0" encoding="UTF-8"?>  | 
db.properties
1  | jdbc.driver=com.mysql.jdbc.Driver  | 
web.xml
1  | <?xml version="1.0" encoding="UTF-8"?>  | 
最终项目结构

咱们来说说今天遇到的坑好吧
- 使用maven搭建ssm框架遇到的spring找不到配置文件问题
 
在打包部署时,为了防止mybatis的mapper文件被过滤掉,在pom文件的build节点下加入了如下代码:
1  | <resources>  | 
然后发布后就悲剧了,提示applicationContext-*文件找不到,报了FileNotFindExeception
1  | Could not resolve bean definition resource pattern [classpath:spring/applicationContext-*…  | 
原因: 
解决方法: 
再添加一个resource节点1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20<!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉。 -->
      <resources>
          <resource>
              <directory>src/main/java</directory>
              <includes>
                  <include>**/*.properties</include>
                  <include>**/*.xml</include>
              </includes>
              <filtering>false</filtering>
          </resource>
          <!-- 如果不添加此节点spring的.xml文件都会被漏掉。 -->
          <resource>
              <directory>src/main/resources</directory>
              <includes>
                  <include>**/*.properties</include>
                  <include>**/*.xml</include>
              </includes>
              <filtering>false</filtering>
          </resource>
      </resources>
- 使用maven的tomcat插件
 
使用了maven的tomcat插件启动项目后,就不能访问tomcat的主页了,我还傻呵呵的去访问,以为自己哪里写错了!!!
