(轉)我的APPFUSE2.0.1開發過程的問題記錄和解決辦法
http://www.pben.cn/read.htm?action=topic&id=8a8181871a519f9c011a54b337e9055d&bid=33&fcpage=1&fcaction=index&tagId=01。怎樣使每次測試時不刪除數據庫中表結構?
解答:將pom.xml配置中的如下代碼屏蔽掉。







































2。怎樣使用外部配置變量?
解答:a。在pom.xml配置文件中加入占位符
如: <!-- FTP settings -->




b。在resources目錄下新建文本文件ftp.properties




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
解答:以下列出3種解決方法,優先選擇方法1。
解決方法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文件。
解決方法3:復制target/test-classes/的WEB-INF文件夾到target/classes目錄下,使得集成測試可以訪問該目錄下的文件。
4。怎樣解決測試報“Embedded error: java.sql.SQLException: ORA-01401: 插入的值對于列過大”錯誤?
解答:檢查hmb2ddl生成的數據表字段的實際類型及大小,再跟test/resources/samples-data.xml里對應的表的測試數據比較,檢查是否跟實際數據庫表中數據類型不匹配。有時appfuse自動產生的測試數據過大造成的,修改測試數據即可。
5。怎樣使用本地mvean_proxy?
解答:本地運行java -jar maven-proxy-standalone-0.2-app.jar maven-proxy.properties,然后在pom.xml庫中修改配置








































6。使用JSF時怎樣向菜單上添加子菜單,及關聯事件處理代碼?
解答:a.首先在ApplicationResources.properties資源配置文件中添加變量
例如:# -- auditReport day tast page --
auditReportDayTask.execute=AuditReport Task Run
auditReportDayTask.executed=AuditReport has been runned successfully.
# -- AuditReport-END
b.向AuditReportForm.java文件中添加事件響應代碼
例如: public String auditDay() {
auditReportManager.autoAuditDay();
addMessage("auditReportDayTask.executed");
return "mainMenu";
}
c.在mainMenu.xhtml文件中添加commandLink
例如:<h:commandLink value="#{text['auditReportDayTask.execute']}" action="#{auditReportForm.auditDay}"/>
7。怎樣向Mvean中installing 3rd party JARs?
解答:To install a JAR in the local repository use the following command:
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
例如:mvn install:install-file -Dfile=quartz-1.6.0.jar -DgroupId=quartz -DartifactId=quartz -Dversion=1.6.0 -Dpackaging=jar
8。怎樣在pom.xml中配置3rd party JARs,使得mvn integration-test集成測試后打包成war文件?
解答:向dependency中添加依賴,通過第7步的安裝就可以從本地庫中引用第三方jar文件了。
例如:









9。怎樣使用Ioc在Spring框架中使用bean自動管理對象?
解答:a.編寫需要被Spring管理的類,如MyFTP.java;
b.在applicationContext.xml或applicationContext-resources.xml中配置bean;
如:
























c.在AuditReportManagerImpl.java類中直接使用xmlParser屬性,該對象已經在auditReportManager由Spring裝載時實例化了。
11。在使用Spring框架時怎樣通過application context訪問資源?
解答:a.通過虛擬路徑來存取.如果我們的資源文件位于CLASSPATH下,我們就可以通過這種方法來獲取資 源文件,獲取代碼如下:
ApplicationContext context = new FileSystemXmlApplicationContext("src/org/spring/test/applicationContext.xml");
Resource resource = context.getResource("classpath:message.properties");
這里需要注意的是classpath:是spring約定的URL虛擬路徑.
b.或通過實際路徑來存取:
獲取代碼如下:
ApplicationContext context = new FileSystemXmlApplicationContext("src/org/spring/test/applicationContext.xml");
Resource resource = context.getResource("file:D:/JProject/SpringTest/src/message.properties");
c.或通過相對路徑來存取:
獲取方法:
ApplicationContext context = new FileSystemXmlApplicationContext("src/org/spring/test/applicationContext.xml");
Resource resource = context.getResource("src/message.properties");
12。怎樣把Resource作為屬性來配置?
解答:a.首先創建待配置bean的java源文件AuditReportManagerImpl.java,該文件中要有Resource類型屬性,如UrlResource,ClassPathResource,FileSystemResource,ServletContextResource,InputStreamResource,ByteArrayResource其中一種資源變量。例如private ClassPathResource xmlResource;
b.然后在applicationContext.xml或applicationContext-resources.xml配置文件中配置該bean;
如:
<!--NamedSQLParser Server-START-->
<bean id="namedSQLParser" class="com.xjgzinfo.app.util.NamedSQLParser">
<property name="xmlResource" value="classpath:nativeSQL.hbm.xml"/>
</bean>
<!--NamedSQLParser Server-END-->
c.通過web.xml中配置的監聽,如
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
該監聽會在web容器啟動時對該web應用實例化ApplicationContext對象,通過a,b兩步的配置ApplicationContext對象會實例化該資源,并獲取classpath下的nativeSQL.hbm.xml資源文件返回給AuditReportManagerImpl.java中的Resource類型屬性,在本例中我的xmlResource屬性就可以在AuditReportManagerImpl中直接使用了。
13。怎樣使用命名查詢?
解答:a.在src/main/resources/目錄下建立命名查詢的配置文件,如:nativeSQL.hbm.xml












































b.在src/main/resources/hibernate.cfg.xml文件中添加資源文件
<mapping resource="nativeSQL.hbm.xml" />
c.在DaoHibernate實現java文件類中就可以通過調用super.getHibernateTemplate().findByNamedQuery(queryName);方法執行命名查詢了。而且super.getHibernateTemplate().findByNamedQueryAndNamedParam()方法支持帶參數的sql語句。
d.注意!命名查詢語句必須給出完整的對應與AuditReport對象屬性的字段,否則會報“nested exception is java.sql.SQLException: 列名無效”的錯誤。當AuditReport對象設定關鍵字時,{auditReport.id}的值不能為NULL,否則會報“java.lang.NullPointerException”的錯誤;{auditReport.id}的值要唯一才能正確返回結果,否則返回的List<AuditReport>中的AuditReport對象都一樣。
14。怎樣使用Dom4j讀取XML文件?
解答:a。導入如下包:
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
b。采用如下語句片段讀取XML節點:
private List namedSQL;// 命名查詢列表,用于存放解析后得到的命名查詢

























c。對以上語句的解釋,xmlResource是資源文件對應的變量,對應的XML文件就是以上13問答用到的nativeSQL.hbm.xml文件。該資源使用方法見以上12解答。XMLHelper.DEFAULT_DTD_RESOLVER是對XML文件中DOCTYPE標記進行解析的解析器,該解析器碰到http://hibernate.sourceforge.net描述資源時首先會到hibernate-3.2.5.ga.jar文件的org/hibernate路徑下尋找指定的dtd文件,如果找不到才會到http://hibernate.sourceforge.net網站讀取該dtd文件。具體使用方法可以參照hibernate-3.2.5.ga.jar/org/hibernate/util/下的XMLHelper.class、ConfigHelper.class和DTDEntityResolver.class
15。測試時報“ Error executing database operation: CLEAN_INSERT
Embedded error: Listener refused the connection with the following error:
ORA-12518, TNS:listener could not hand off client connection
The Connection des.c.r.i.p.tor used by the client was:
localhost:1521:Ora9i”怎么處理?
解答:提示這個錯誤的原因是由于當前配置的Ora9i數據庫不能連接。檢查網絡或開啟數據庫實例。
16。使用Oracle作數據庫時,PL/SQL Developer工具連接數據庫正常,但是測試時報“[INFO] Error executing database operation: CLEAN_INSERT
Embedded error: my_table_name_t”,是怎么回事?
解答:這是因為在appfuse中數據庫配置方案名要大寫,如下配置:






















17。采用Hibernate3時對于大批量保存操作該怎么處理?
解答:對于大批量的數據入庫操作,要定量刷新緩存,采用super.getSession().flush(),Hibernate會自動生成原始SQL語句,將內存中的數據持久化到數據庫中。否則會導致內存溢出。采用如下語句:


























posted on 2008-06-25 22:10 gdufo 閱讀(1823) 評論(0) 編輯 收藏 所屬分類: Appfuse