好久没有写java了,昨天学了下maven,不用手动的下载和添加jar包,实在是太方便。
-----------------------------------------------------------------------------------------------------------------
搭了下ssm。spring和mybatis集成时遇到太多bug:
bug1. 找不到dao对应的xml
Caused by: java.lang.IllegalArgumentException: Could not resolve resource location pattern [classpath:xin/redips/urls/mapper/*.xml]:
class path resource [xin/redips/urls/mapper/] cannot be resolved to URL because it does not exist
去target/classes文件夹下看了下还真是没有,maven没有把xml拷贝到classpath下,需要加上:
<build>
...
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource> <resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
<filtering>true</filtering>
</resource> </resources>
</build>
bug2. Cannot load JDBC driver class 'com.mysql.jdbc.Driver '
原因是配置文件多加了个空格。。
bug3. No suitable driver
网上说:Java.sql.SQLException: No suitable driver found for这个异常的发生,原因有二:
一,在可寻的路径下没有合适的数据库驱动。
二,数据库连接时提供的url不正确。
maven已经下好了jar包,所以不是原因一。而倒数第二个异常是:
我url明明写的是:
原来是pom.xml中定义的url覆盖了properties中定义的url.