Maven 搭建SSM pom.xml報錯注意項
1. 找不到mapper對映檔案異常:Invalid bound statement (not found)
eg: Invalid bound statement (not found): cn.wz.ssm.mapper.ItemMapper.selectByExampleWithBLO
解:此時需要在pom.xml檔案中新增配置節點程式碼,如果不配置,mybatis的mapper.xml檔案都會被漏掉。
<build> <resources> <resource> <directory>src/main/java</directory> <!-- 此配置不可缺,否則mybatis的Mapper.xml將會丟失 --> <includes> <include>**/*.xml</include> </includes> </resource> <!--指定資源的位置--> <resource> <directory>src/main/resources</directory> </resource> </resources> </build>
2. 注意 classspath: 與 classpath*:的區別:
classpath:只會到你指定的class路徑中查詢找檔案;
classpath*:不僅包含class路徑,還包括jar檔案中(class路徑)進行查詢.
例: 1.在web.xml中定義:classpath*:META-INF/spring/application-*.xml
那麼在META-INF/spring這個資料夾底下的所有application-*.xml都會被載入到上下文中
(包括META-INF/spring application-*.xml,META-INF/spring子資料夾的application-*.xml以及jar中的 application-*.xml)
2. 如果web.xml中定義是:classpath:META-INF/spring/application-context.xml
那麼只有META-INF/spring底下的application-*.xml會被載入到上下文中
3.pom.xml中的Java ee 包 需要和jdk對應,activation與java ee 版本對應
<!-- java ee包 -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<!-- java ee包 end-->
4.需要在pom.xml 中配置maven 編譯外掛 的版本以及啟動的jdk版本
<!--maven 配置編譯外掛-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5</version>
<configuration>
<source>1.8</source><!--jdk版本-->
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
<!--maven 配置編譯外掛 end-->
可參考 https://blog.csdn.net/u013412066/article/details/51967602
5.IDEA tomcat啟動錯誤可參考三個地方