一、开发工具:idea
二、数据库:mysql
三、语言:java
四、问题记录:
1、编写测试类进行测试的时候,需要注意通过dependency进行依赖另一个模块时候,scope为test的不能继承过来,例如:
xxx-commons模块下的pom.xml:
<!-- 单元测试 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
当xxx-manager依赖xxx-commons的时候,上面两个jar不能依赖过来:
<dependency>
<groupId>com.ssl</groupId>
<artifactId>xxx-commons</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
此时,junit和spring-test并不会引入到xxx-manager模块下面,但是当xxx-manager是xxx-commons的子模块时,便可以引用到。
2、使用spring-test、junit编写测试类的时候,需要引入
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
3、注意classpath*和classpath的区别:classpath*会将各个模块下的classpath都扫描一遍,而classpath只扫描当前模块。
4、在使用mybatis时,当sql的xml文件和mapper文件不在同一个目录下,配置sqlSessionFactory的时候,需要用指定mapperLocations,例如:
<!-- 配置sqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- mybatis配置文件,加载了分页插件 -->
<property name="configLocation" value="classpath:mybatis/SqlMapConfi.xml"/>
<property name="dataSource" ref="dataSource"/>
<!-- 指定mapping.xml文件 -->
<property name="mapperLocations" value="classpath:com/ssl/shop/mapper/xml/*.xml"/>
</bean>
<!-- 配置扫描包,加载mapper代理对象 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.ssl.shop.mapper"/>
</bean>
5、idea中,通过点击右侧的maven projects,会有各个maven项目的依赖以及插件详情,也可选中插件,直接运行,但是Plugins下的install-install:install命令会报错,此时应该选中上方的方形M图标(Execute maven Goal),选择模块的目录,然后填入install命令,最后点击Execute即可。
6、执行install的时候,也会去运行一遍测试类中的方法,假如测试类中的方法运行失败,也会导致该模块install失败,需要注意一下。