駱昊的Java空間

          傳道、授業、解惑,何有于我哉! Java SE / Java ME / Java EE / C / C++ / C#

          2010年2月5日

          關于MySQL的簡單總結

               摘要:   MySQL是最著名的開源數據庫,容易上手且功能強大,Yahoo!、BBC News等著名站點都使用了MySQL數據庫進行數據存儲 在Linux環境中可以通過/etc/my.cnf對MySQL服務器進行配置(在Windows中是一個叫my.ini的文件),有接近300個配置參數可以用來在啟動MySQL服務器時控制其行為(包括:內存、日志、錯誤報告等等) 在Linux環境中可以通...  閱讀全文

          posted @ 2011-02-20 05:48 駱昊 閱讀(290) | 評論 (0)編輯 收藏

          Struts 2.1.x + Spring 2.5.x + Hibernate 3.3.x整合需要的JAR包

           下面這個表相信對很多人都有用:

          jar包名稱

          所在位置

          說明

          antlr-2.7.6.jar

          hibernate/lib/required

          解析HQL

          aspectjrt

          spring/lib/aspectj

          AOP

          aspectjweaver

          ..

          AOP

          cglib-nodep-2.1_3.jar

          spring/lib/cglib

          代理,二進制增強

          common-annotations.jar

          spring/lib/j2ee

          @Resource

          commons-collections-3.1.jar

          hibernate/lib/required

          集合框架

          commons-fileupload-1.2.1.jar

          struts/lib

          struts

          commons-io-1.3.2

          struts/lib

          struts

          commons-logging-1.1.1

          單獨下載最新版本

          struts

          spring

          dom4j-1.6.1.jar

          hibernate/required

          解析xml

          ejb3-persistence

          hibernate-annotation/lib

          @Entity

          freemarker-2.3.13

          struts/lib

          struts

          hibernate3.jar

          hibernate

          hibernate-annotations

          hibernate-annotation/

          hibernate-common-annotations

          hibernate-annotation/lib

          javassist-3.9.0.GA.jar

          hiberante/lib/required

          hibernate

          jta-1.1.jar

          ..

          hibernate transaction

          junit4.5

          mysql-

          ognl-2.6.11.jar

          struts/lib

          slf4j-api-1.5.8.jar

          hibernate/lib/required

          hibernate-log

          slf4j-nop-1.5.8.jar

          hibernate/lib/required

          spring.jar

          spring/dist

          struts2-core-2.1.6.jar

          struts/lib

          xwork-2.1.2.jar

          struts/lib

          struts2

          commons-dbcp

          spring/lib/jarkata-commons

          commons-pool.jar

          ..

          struts2-spring-plugin-2.1.6.jar

          struts/lib

          posted @ 2010-02-27 18:23 駱昊 閱讀(845) | 評論 (0)編輯 收藏

          Spring AOP之Introduction(@DeclareParents)簡介

          Spring的文檔上對Introduction這個概念和相關的注解@DeclareParents作了如下介紹:

          Introductions (known as inter-type declarations in AspectJ) enable an aspect to declare that advised objects implement a given interface, and to provide an implementation of that interface on behalf of those objects.
          An introduction is made using the @DeclareParents annotation. This annotation is used to declare that matching types have a new parent (hence the name).


          在這段介紹之后還給出了一個例子,對于初學者要理解這段話以及后面的例子還是蠻困難的,因此下面用一個簡單的例子告訴大家什么是Introduction以及如何使用@DeclareParents注解。

          對于Introduction這個詞,個人認為理解成引入是最合適的,其目標是對于一個已有的類引入新的接口(有人可能會問:有什么用呢?簡單的說,你可以把當前對象轉型成另一個對象,那么很顯然,你就可以調用另一個對象的方法了),看一個例子就全明白了。

          假設已經有一個UserService類提供了保存User對象的服務,但是現在想增加對User進行驗證的功能,只對通過驗證的User提供保存服務,在不修改UserService類代碼的前提下就可以通過Introduction來解決。

          首先定義一個Verifier接口,里面定義了進行驗證的方法validate(),如下所示:
          package com.jackfrued.aop;

          import com.jackfrued.models.User;

          public interface Verifier {

              
          public boolean validate(User user);
          }

          接下來給出該接口的一個實現類BasicVerifier,如下所示:
          package com.jackfrued.aop;

          import com.jackfrued.models.User;

          public class BasicVerifier implements Verifier {

              @Override
              
          public boolean validate(User user) {
                  
          if(user.getUsername().equals("jack"&& user.getPassword().equals("1234")) {
                      
          return true;
                  }

                  
          return false;
              }

          }


          如何才能為UserService類增加驗證User的功能呢,如下所示定義Aspect:
          package com.jackfrued.aop;

          import org.aspectj.lang.annotation.Aspect;
          import org.aspectj.lang.annotation.DeclareParents;
          import org.springframework.stereotype.Component;

          @Aspect
          @Component
          public class MyAspect {
              @DeclareParents(value
          ="com.tsinghuait.services.UserService"
                      defaultImpl
          =com.tsinghuait.aop.BasicVerifier.class)
              
          public Verifier verifer;
          }
          接下來就可以將UserService對象轉型為Verifier對象并對用戶進行驗證了,如下所示:
          package com.jackfrued.main;

          import org.springframework.context.ApplicationContext;
          import org.springframework.context.support.ClassPathXmlApplicationContext;

          import com.jackfrued.aop.Verifier;
          import com.jackfrued.models.User;
          import com.jackfrued.services.Service;

          class Test {

              
          public static void main(String[] args) {
                  User user1 
          = new User();
                  user1.setUsername(
          "abc");
                  user1.setPassword(
          "def");
                  
                  ApplicationContext factory 
          = new ClassPathXmlApplicationContext("config.xml");
                  Service s 
          = (Service) factory.getBean("service");
                  Verifier v 
          = (Verifier) s;
                  
          if(v.validate(user1) {
                      System.out.println(
          "驗證成功");
                      s.serve(user1);
                  }

                  
              }

          }

          這樣,上面代碼中的user1是不會被服務的,當然是因為沒有通過驗證啦!

          這樣一說,是不是大概明白什么是Introduction了呢,其實@DeclareParents用起來也很簡單吧!

          至于配置文件和其他內容請參考完整源代碼:/Files/jackfrued/Spring-introduction.rar

          posted @ 2010-02-27 14:09 駱昊 閱讀(4803) | 評論 (0)編輯 收藏

          Spring AOP編程中的一個小問題

          在用Spring 2.5.6 + jdk 1.7開發時,使用@PointCut注解定義切入點時會導致以下錯誤

          error at ::0 can't find referenced pointcut XXX

          這應該算是一個Bug吧,不過只要在類路徑下放最新的aspectjrt.jar和aspectjweaver.jar
          就可以避免這個問題了。可以去到eclipse的官方網站下載上面的JAR包,下載地址:

          http://www.eclipse.org/aspectj/downloads.php

          posted @ 2010-02-27 12:36 駱昊 閱讀(423) | 評論 (0)編輯 收藏

          [轉]基于需求測試(RBT)

          測試人員的首要職責是找bug,但是最重要、最根本的職責應該是在軟件產品發布前確保公司的軟件產品滿足顧客的需求。

            測試組采用RBT(Requirements-based testing),基于需求的測試方法會使測試更加有效,因為它使測試專注于質量問題產生的根源。

                        

            研究報告指出,多年來,大部分的軟件項目不能按計劃完成,不能有效控制成本。大部分項目失敗的首要原因是軟件質量差,導致大量的返工、重新設計和編碼。其中軟件質量差的兩大原因是:軟件需求規格說明書的錯誤、有問題的系統測試覆蓋。

          需求規格說明書中的錯誤

            我們經常聽到最終用戶抱怨、不用我們的軟件,而這些軟件還通過了嚴格的測試和QA。對于這點我們不會感到驚訝,原因是我們知道需求從一開始就是錯誤的。

            一項調查(James Martin (“An Information Systems Manifesto,” Prentice Hall, 1984)表明56%的缺陷其實是在軟件需求階段被引入的。而這其中的50%是由于需求文檔編寫有問題、不明確、不清晰、不正確導致的。剩下的50%是由于需求的遺漏導致的。

          有問題的測試覆蓋

            要獲得滿意的測試覆蓋率是很難的。尤其現在的系統都比較復雜,功能場景很多,邏輯分支很多,要做到完全的覆蓋幾乎不可能。

            再者,需求的變更往往缺乏控制,需求與測試用例之間往往缺乏可跟蹤性。

                       

          RBT三大最佳實踐

          1、  Test early and often.盡早測試,頻繁地測試

            確認需求的業務價值。

            各利益相關方應該對需求進行評審。

            通過用例檢查需求的完整性

            應用語言分析技術確保需求文檔清晰一致,不會引起同一問題不同人有不同的解釋。

           2、  Test with your head, not your gut.不要單憑經驗測試

            不要依賴測試人員的經驗來設計測試用例,應該采用系統、嚴格的測試用例設計方法,而不是依賴有經驗的測試人員的技巧。通過這樣的方式來增加測試覆蓋的有效性。格式化、結構化的需求文檔有助于測試人員評估需求的測試覆蓋率。

            通過測試用例評審來檢查測試用例存在的錯誤,并且找出需求的不足之處。

           3、  Test with measurement and improvement in mind.測試過程中要保持度量

            在使用基于需求的測試方法的過程中,保持對需求的可追蹤性非常重要。保持需求與測試用例及測試之間的可追蹤性有助于監視進度、度量覆蓋率,當然也有助于控制需求變更。

          posted @ 2010-02-05 09:50 駱昊 閱讀(302) | 評論 (0)編輯 收藏

          <2010年2月>
          31123456
          78910111213
          14151617181920
          21222324252627
          28123456
          78910111213

          導航

          統計

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 临朐县| 绍兴市| 远安县| 青铜峡市| 贵南县| 库伦旗| 金乡县| 广饶县| 潞城市| 略阳县| 南靖县| 桐梓县| 万山特区| 林西县| 孟州市| 天峨县| 镇原县| 日土县| 万山特区| 浦县| 曲阜市| 黄骅市| 眉山市| 灌南县| 前郭尔| 成武县| 闵行区| 祁连县| 扬州市| 湛江市| 行唐县| 三亚市| 梁河县| 安图县| 罗江县| 青河县| 买车| 乌鲁木齐市| 望谟县| 峨眉山市| 雷山县|