1.怎样使每次测试时不删除数据库中表结构?
解答:将pom.xml配置中的如下代码屏蔽掉。
| <!--plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>hibernate3-maven-plugin</artifactId> <version>2.0-alpha-2</version> <configuration> <components> <component> <name>hbm2ddl</name> <implementation> annotationconfiguration </implementation> </component> </components> <componentProperties> <drop>true</drop> <jdk5>true</jdk5> <propertyfile> target/classes/jdbc.properties </propertyfile> <skip>${maven.test.skip}</skip> </componentProperties> </configuration> <executions> <execution> <phase>process-test-resources</phase> <goals> <goal>hbm2ddl</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupId>${jdbc.groupId}</groupId> <artifactId>${jdbc.artifactId}</artifactId> <version>${jdbc.version}</version> </dependency> </dependencies> </plugin--> |
2.怎样使用外部配置变量?
解答:a。在pom.xml配置文件中加入占位符
| <!-- FTP settings --> <ftp.url>135.224.82.4</ftp.url> <ftp.username>ls</ftp.username> <ftp.password>FdbEgT+7</ftp.password> <ftp.path>/data/jyf/0000/SRC/</ftp.path> b。在resources目录下新建文本文件ftp.properties ftp.url=${ftp.url} ftp.username=${ftp.username} ftp.password=${ftp.password} ftp.path=${ftp.path} c。在引用的applicationContext文件节点propertyConfigurer中添加<value>classpath:ftp.properties</value> d。这时就可以直接使用占位符了 如: <!--FTP Server-START--> <bean id="myFTP" class="com.xjgzinfo.app.util.MyFTP" lazy-init="true" destroy-method="destroy"> <property name="server" value="${ftp.url}" /> <property name="user" value="${ftp.username}" /> <property name="password" value="${ftp.password}" /> <property name="path" value="${ftp.path}" /> </bean> <!--FTP Server-END--> |
3.测试Dao时报如下错误该怎么解决?
Unsatisfied dependency expressed through bean property 'interfaceDataDefineDao': Set this property value or disable dependency checking for this bean
解答:解决方法1:测试初始化没有自动加载webapp/WEB-INF/applicationContext.xml文件,把该文件复制到target\classes\目录下即可。
解决方法2:修改build path将src/main/webapp的out put folder修改成default output folder(实际是target/classes),此方法实际是将webapp里的文件都复制到target/classes里,使得测试过程可以访问到applicationContext.xml文件。
4.怎样解决测试报“Embedded error: java.sql.SQLException: ORA-01401: 插入的值对于列过大”错误?
解答:检查hmb2ddl生成的数据表字段的实际类型及大小,再跟test/resources/samples-data.xml里对应的表的测试数据比较,检查是否跟实际数据库表中数据类型不匹配。有时appfuse自动产生的测试数据过大造成的,修改测试数据即可。
