posts - 167,  comments - 30,  trackbacks - 0
               摘要:   閱讀全文
          posted @ 2017-09-04 16:33 David1228 閱讀(313) | 評(píng)論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2017-08-02 11:41 David1228 閱讀(335) | 評(píng)論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2017-07-24 19:10 David1228 閱讀(11409) | 評(píng)論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2017-07-19 18:10 David1228 閱讀(3446) | 評(píng)論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2017-06-06 23:10 David1228 閱讀(298) | 評(píng)論 (0)編輯 收藏
          Netty客戶端與服務(wù)端通信
          posted @ 2017-06-06 23:09 David1228 閱讀(250) | 評(píng)論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2017-05-30 19:26 David1228 閱讀(3298) | 評(píng)論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2017-05-30 19:25 David1228 閱讀(1266) | 評(píng)論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2016-12-22 23:01 David1228 閱讀(4628) | 評(píng)論 (2)編輯 收藏
               摘要:   閱讀全文
          posted @ 2016-11-04 23:44 David1228 閱讀(2310) | 評(píng)論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2016-07-28 17:57 David1228 閱讀(406) | 評(píng)論 (0)編輯 收藏
               摘要: JVM調(diào)優(yōu)總結(jié) + jstat 分析jstat -gccause pid 1 每格1毫秒輸出結(jié)果jstat -gccause pid 2000 每格2秒輸出結(jié)果不斷的在屏幕打印出結(jié)果  S0     S1     E     &n...  閱讀全文
          posted @ 2016-01-03 23:26 David1228 閱讀(3005) | 評(píng)論 (2)編輯 收藏
               摘要:   閱讀全文
          posted @ 2015-12-27 16:49 David1228 閱讀(1099) | 評(píng)論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2015-10-31 12:37 David1228 閱讀(677) | 評(píng)論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2015-10-30 20:20 David1228 閱讀(2891) | 評(píng)論 (0)編輯 收藏
          轉(zhuǎn)載文章:http://www.qixing318.com/article/by-lua-adhesive-nginx-ecological-environment.html
          posted @ 2015-09-08 13:22 David1228 閱讀(520) | 評(píng)論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2015-09-08 09:34 David1228| 編輯 收藏
               摘要:   閱讀全文
          posted @ 2015-07-29 13:48 David1228 閱讀(5563) | 評(píng)論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2014-12-03 23:56 David1228 閱讀(28352) | 評(píng)論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2013-11-19 11:48 David1228 閱讀(23759) | 評(píng)論 (1)編輯 收藏
               摘要:   閱讀全文
          posted @ 2013-11-18 18:01 David1228 閱讀(2912) | 評(píng)論 (4)編輯 收藏
               摘要:   閱讀全文
          posted @ 2013-10-31 17:32 David1228 閱讀(713) | 評(píng)論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2013-10-14 09:50 David1228 閱讀(21772) | 評(píng)論 (6)編輯 收藏
          Hibernate不支持left join帶on的條件查詢。
          解決辦法:使用原生SQL或者使用HQL方式需要修改hbm文件(如果項(xiàng)目中大部分不適用級(jí)聯(lián)配置情況下)
          需求是查詢網(wǎng)絡(luò)信息,網(wǎng)絡(luò)信息中關(guān)聯(lián)了分區(qū)、網(wǎng)絡(luò)IP(1個(gè)網(wǎng)絡(luò)--N個(gè)網(wǎng)絡(luò)IP),網(wǎng)橋信息.
          HQL:
          public void queryVnets(Page page) {
                  StringBuffer hql = new StringBuffer();
                  hql.append("select new Map(vn.id as id, vn.vnName as vnName, b.name as vnType, ");
                  hql.append("vn.vnIptype as vnIptype, vn.vnIp as vnIp,vn.vnNat as vnNat, vn.vnFlag as vnFlag, ");
                  hql.append("vn.vnetFlag as vnetFlag, (case when sum(vmvn.state)='0' then 0 else 1 endas vnState, ");
                  hql.append("vn.useType as useType, vn.createTime as createTime, ");
                  hql .append("zone.oneName as oneName, zone.oneHypervisor as oneHypervisor, zone.oneSeq as oneSeq) ");
                  hql.append("from VnetTable vn, ZoneTable zone, BridgeTable b ");
                  hql.append("left join fetch vn.VnTables vmvn where zone.id = vn.zoneId and vn.vnType = b.id ");

                  ... ...
                  hql.append(" group by vn.id");
                  if (vnState != null && !"".equals(vnState)) {
                      if ("0".equals(vnState)) {
                          hql.append(" having sum(vmvn.state)=0");
                      } else if ("1".equals(vnState)) {
                          hql.append(" having sum(vmvn.state)!=0");
                      }
                  }
              }

          hbm配置文件:
          <?xml version="1.0" encoding="utf-8"?>
          <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
          <!-- 
              Mapping file autogenerated by MyEclipse Persistence Tools
          -->
          <hibernate-mapping>
              <class name="com.base.mapping.VnetTable" table="vnet_table" >
                  <id name="id" type="java.lang.String">
                      <column name="ID" length="32" />
                      <generator class="uuid.hex" />
                  </id>
                  <property name="vnId" type="java.lang.Long">
                      <column name="VN_ID">
                          <comment>創(chuàng)建虛擬網(wǎng)絡(luò)時(shí)得到的ID</comment>
                      </column>
                  </property>
                   ...
                  <property name="zoneId" type="java.lang.String">
                      <column name="ZONE_ID" length="32">
                          <comment>分區(qū)ID</comment>
                      </column>
                  </property>
                  <property name="vlanId" type="java.lang.Integer">
                      <column name="VLAN_ID">
                          <comment>VLAN_ID</comment>
                      </column>
                  </property>
                  <set name="vnTables" lazy="false" order-by="id asc" inverse="false" fetch="join" cascade="all">
                      <key column="VN_NID"/>
                      <one-to-many class="com.base.mapping.VnTable"/>
                  </set>
              </class>
          </hibernate-mapping>

          理解inverse和cascade,可以參考:http://blog.csdn.net/wkcgy/article/details/6271321
          總結(jié): 
          <one-to-many>中,建議inverse=”true”,由“many”方來(lái)進(jìn)行關(guān)聯(lián)關(guān)系的維護(hù) 
          <many-to-many>中,只設(shè)置其中一方inverse=”false”,或雙方都不設(shè)置 
          Cascade,通常情況下都不會(huì)使用。特別是刪除,一定要慎重。
          操作建議 
            一般對(duì)many-to-one和many-to-many不設(shè)置級(jí)聯(lián),這要看業(yè)務(wù)邏輯的需要;對(duì)one-to-one和one-to-many設(shè)置級(jí)聯(lián)。
            many-to-many關(guān)聯(lián)關(guān)系中,一端設(shè)置inverse=”false”,另一端設(shè)置為inverse=”true”。在one-to-many關(guān)聯(lián)關(guān)系中,設(shè)置inverse=”true”,由多端來(lái)維護(hù)關(guān)系表










          posted @ 2013-09-12 11:57 David1228 閱讀(16703) | 評(píng)論 (2)編輯 收藏
          -- 以下兩個(gè)查詢效率相當(dāng),查詢時(shí)間均為0.0xx秒,~ 但是Hibernate HQL不支持from后面接子查詢,可以直接使用SQL方式解決,ibatis當(dāng)然可以用了。
          SELECT count(*from (
          SELECT sum(t2.STATE) as vnSum, t1.ID FROM
          vnetinfo_table t1, vm_vn_table t2 
          where t1.ID = t2.VN_NID and t1.ZONE_ID = '4028a49c3facdf26013fae12531b286e' GROUP BY t1.ID) t where t.vnSum = 0;

          SELECT count(*) FROM vnetinfo_table v ,(
          SELECT sum(t2.STATE) as vnSum, t1.ID as idd FROM
          vnetinfo_table t1, vm_vn_table t2 
          where t1.ID = t2.VN_NID and t1.ZONE_ID = '4028a49c3facdf26013fae12531b286e' GROUP BY t1.ID) t
          where v.ID = t.idd and t.vnSum = 0;

          -- 查詢效率太低了,查詢時(shí)間均為0.5xx秒左右。要比以上兩個(gè)SQL耗時(shí)很多倍。~ Hibernate支持在where后用子查詢作為查詢條件。
          SELECT count(*) FROM vnetinfo_table v WHERE v.id in 
          (SELECT CASE WHEN SUM(t2.STATE)=0 THEN t1.ID ELSE '' END
          FROM vnetinfo_table t1, vm_vn_table t2 
          where t1.ID = t2.VN_NID and t1.ZONE_ID = '4028a49c3facdf26013fae12531b286e' GROUP BY t1.ID);

          -- 使用join方式替換in 查詢時(shí)間均為0.09x秒左右。明顯提高了效率,但是Hibernate HQL任然不支持在這種聯(lián)合子查詢方式。
          SELECT count(*) FROM vnetinfo_table v INNER JOIN (SELECT CASE WHEN SUM(t2.STATE)=0 THEN t1.ID ELSE '' END as idd
          FROM vnetinfo_table t1, vm_vn_table t2 
          WHERE t1.ID = t2.VN_NID and t1.ZONE_ID = '4028a49c3facdf26013fae12531b286e' GROUP BY t1.ID) t ON v.ID = t.idd and t.idd IS not NULL;

          附:Mysql中關(guān)于Exists用法的介紹請(qǐng)參見(jiàn):http://www.nowamagic.net/librarys/veda/detail/639
          posted @ 2013-08-21 13:47 David1228 閱讀(3765) | 評(píng)論 (2)編輯 收藏
          md5sum命令詳解:
          linux下的shell命令 ,制作md5碼 也用于軟件的md5校驗(yàn)
          MD5算法常常被用來(lái)驗(yàn)證網(wǎng)絡(luò)文件傳輸?shù)耐暾裕乐刮募蝗舜鄹摹D5 全稱是報(bào)文摘要算法(Message-Digest Algorithm 5),此算法對(duì)任意長(zhǎng)度的信息逐位進(jìn)行計(jì)算,產(chǎn)生一個(gè)二進(jìn)制長(zhǎng)度為128位(十六進(jìn)制長(zhǎng)度就是32位)的“指紋”(或稱“報(bào)文摘要”),不同的文件產(chǎn)生相同的報(bào)文摘要的可能性是非常非常之小的。
          在linux或Unix上,md5sum是用來(lái)計(jì)算和校驗(yàn)文件報(bào)文摘要的工具程序。一般來(lái)說(shuō),安裝了Linux后,就會(huì)有md5sum這個(gè)工具,直接在命令行終端直接運(yùn)行。
          1、使用md5sum來(lái)產(chǎn)生指紋(報(bào)文摘要)命令如下:
          md5sum filename > filename.md5 或者
          md5sum filename >>filename.md5
          也可以把多個(gè)文件的報(bào)文摘要輸出到一個(gè)md5文件中,這要使用通配符*,比如某目錄下有幾個(gè)iso文件,要把這幾個(gè)iso文件的摘要輸出到iso.md5文件中,命令如下:
          md5sum *.iso > iso.md5
          2、使用md5報(bào)文摘要驗(yàn)證文件,方法有二:
          把下載的文件file和該文件的file.md5報(bào)文摘要文件放在同一個(gè)目錄下,然后用如下命令進(jìn)行驗(yàn)證:
          md5sum -c file.md5
          然后如果驗(yàn)證成功,則會(huì)輸出:正確結(jié)果。
          實(shí)戰(zhàn)案例:
          需求:虛擬機(jī)存在多份備份,當(dāng)進(jìn)行備份恢復(fù)時(shí),要求檢查源備份壓縮文件的完整性。那么可以通過(guò)md5這種方式來(lái)驗(yàn)證。
          壓縮備份文件并生成md5碼,部分shell腳本如下:
          #----------------------------------
          log "Compressing and moving $SRC_PATH"
          exec_and_log "$SSH $SRC_HOST mkdir -p ${SRC_PATH}_compress"
          for file in `$SSH $SRC_HOST ls $SRC_PATH | grep -v $SN_SIGN`
          do
               exec_and_log "$SSH $SRC_HOST cd $SRC_PATH;sudo chmod -R +r $SRC_PATH/*;tar -Sczvf ${SRC_PATH}_compress/${file}.tgz ${file}"
          done
          #----------------------------------

          #--------------md5 begin-----------------
          log "Create backup.md5"
          exec_and_log "$SSH $SRC_HOST $MD5SUM ${SRC_PATH}_compress/*.tgz > ${SRC_PATH}_compress/backup.md5"
          #--------------md5 end-----------------

          #其中 exec_and_log是另一個(gè)公共腳本中定義的。shell中可以通過(guò)點(diǎn)(.)的方式將腳本引入。該函數(shù)內(nèi)如下:
          # Executes a command, if it fails returns error message and exits
          # If a second parameter is present it is used as the error message when
          # the command fails
          function exec_and_log
          {
              message=$2

              EXEC_LOG_ERR=`$1 2>&1 1>/dev/null`
              EXEC_LOG_RC=$?

              if [ $EXEC_LOG_RC -ne 0 ]; then
                  log_error "Command \"$1\" failed: $EXEC_LOG_ERR"

                  if [ -n "$2" ]; then
                      error_message "$2"
                  else
                      error_message "Error executing $1: $EXEC_LOG_ERR"
                  fi
                  exit $EXEC_LOG_RC
              fi
          }

          # Logs a message, alias to log_info
          function log
          {
              log_info "$1"
          }

          # Log function that knows how to deal with severities and adds the
          # script name
          function log_function
          {
              echo "$1: $SCRIPT_NAME: $2" 1>&2
          }

          # Logs an info message
          function log_info
          {
              log_function "INFO" "$1"
          }

          # Logs an error message
          function log_error
          {
              log_function "ERROR" "$1"
          }

          # This function is used to pass error message to the mad
          function error_message
          {
              (
                  echo "ERROR MESSAGE --8<------"
                  echo "$1"
                  echo "ERROR MESSAGE ------>8--"
              ) 1>&2
          }

          生成的backup.md5內(nèi)容:
          $ md5sum *.tgz > backup.md5 
          2c07174d451a687bc0e401b1dc7d84b8  checkpoint.1376892493.tgz
          57a18d7f6eed36565b9012e519985130  checkpoint.1376903188.tgz
          b652990806e58a81b41dc1b23db9adda  checkpoint.1376904023.tgz
          f4e7adb46a8fde2643e082875cc60e21  checkpoint.1376904289.tgz
          ad2a59902652e2896b35507417b7016f  checkpoint.tgz
          4bd43eac64f238bb35c7194816da7d23  deployment.0.tgz
          ee3d9266cf92f7540cc75a94343bc20a  deployment.7.tgz
          fcd5aae37354b5cb66f4b90544eaa5c3  disk.0.tgz
          c1ef6d911b441660ec2d1e44b5a56f66  disk.1.iso.tgz
          25eae70a31a7c7cff3baade4cd65fe82  disk.1.tgz

          檢查備份文件是否完整:
          exec_and_log "$SSH $SRC_HOST $MD5SUM -c ${SRC_PATH}/backup.md5"

          檢測(cè)結(jié)果:
          $ md5sum -c backup.md5 
          checkpoint.1376892493.tgz: OK
          checkpoint.1376903188.tgz: OK
          checkpoint.1376904023.tgz: OK
          checkpoint.1376904289.tgz: OK
          checkpoint.tgz: OK
          deployment.0.tgz: OK
          deployment.7.tgz: OK
          disk.0.tgz: OK
          disk.1.iso.tgz: OK
          disk.1.tgz: OK
          posted @ 2013-08-20 11:34 David1228 閱讀(2447) | 評(píng)論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2013-08-20 09:46 David1228 閱讀(404) | 評(píng)論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2013-08-20 09:44 David1228 閱讀(401) | 評(píng)論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2013-07-24 16:11 David1228 閱讀(33419) | 評(píng)論 (0)編輯 收藏
               摘要: 根據(jù)官方的說(shuō)法,在ibatis3,也就是Mybatis3問(wèn)世之前,Spring3的開(kāi)發(fā)工作就已經(jīng)完成了,所以Spring3中還是沒(méi)有對(duì)Mybatis3的支持。因此由Mybatis社區(qū)自己開(kāi)發(fā)了一個(gè)Mybatis-Spring用來(lái)滿足Mybatis用戶整合Spring的需求。下面就將通過(guò)Mybatis-Spring來(lái)整合Mybatis跟Spring的用法做一個(gè)簡(jiǎn)單的介紹。MapperFactoryB...  閱讀全文
          posted @ 2013-07-10 18:07 David1228 閱讀(21442) | 評(píng)論 (2)編輯 收藏

          不得不承認(rèn)的是,在目前的web應(yīng)用開(kāi)發(fā)中,Spring的應(yīng)用越來(lái)越廣泛,其地位變得相當(dāng)重要。而在最近推出的Spring 3.2版本中,又引入了一些新的值得關(guān)注的特性。本文中將介紹其中一些值得關(guān)注的新特性。

          一 不再需要web.xml

           在新的Spring 3.2中,可以不再需要web.xml這個(gè)文件了,這得益于Servlet 3.0的新特性。

          其中,可以使用@WebServlet在需要調(diào)用的servlet中,使用注解去設(shè)置servlet中的映射關(guān)系。這樣的話,就可以不再象以往那樣要通過(guò)在web.xml中對(duì)servlet進(jìn)行配置,十分方便。

          此外,Servlet 3.0提供了既能在容器中動(dòng)態(tài)注冊(cè)servlet的方法,也提供了通過(guò)實(shí)現(xiàn)

          ServletContainerInitializer接口的方法實(shí)現(xiàn)在容器啟動(dòng)階段為容器動(dòng)態(tài)注冊(cè)Servlet、Filter和listeners。容器會(huì)在應(yīng)用的啟動(dòng)階段,調(diào)用所有實(shí)現(xiàn)ServletContainerInitializer接口類中的onStartup()方法。而Spring 3.2中,則進(jìn)一步簡(jiǎn)化了這點(diǎn),只需要實(shí)現(xiàn)WebApplicationInitializer接口就可以了,其中提供了一個(gè)相關(guān)的實(shí)現(xiàn)類--AbstractContextLoaderInitializer,它可以動(dòng)態(tài)注冊(cè)DispatcherServlet。這意味著,只要spring-webmvc.jar放置在web應(yīng)用的web-inf/lib中,就可以調(diào)用Dispatcher servlet了。可以參考如下的例子(來(lái)自Spring文檔):

          1. public class MyWebApplicationInitializer implements WebApplicationInitializer { 
          2.  
          3.     @Override 
          4.     public void onStartup(ServletContext container) { 
          5.         ServletRegistration.Dynamic registration = container.addServlet("dispatcher"new DispatcherServlet()); 
          6.         registration.setLoadOnStartup(1); 
          7.         registration.addMapping("/example/*"); 
          8.     } 
          9.  

          二 支持Java編程式配置在Spring mvc 3.2中,一個(gè)不錯(cuò)的特性就是在之前版本中支持使用Java代碼配置各種依賴注入的基礎(chǔ)上,進(jìn)一步簡(jiǎn)化了配置。關(guān)于使用Java編程式配置的好處,可以通過(guò)下面這個(gè)鏈接文章的介紹去學(xué)習(xí)

          http://blog.frankel.ch/consider-replacing-spring-xml-configuration-with-javaconfig)。
          在Spring mvc 3.2中,提供了AbstractContextLoaderInitialize的一個(gè)子類AbstractAnnotationConfigDispatcherServletInitializer去實(shí)現(xiàn)零XML配置的效果,只需要?jiǎng)?chuàng)建的類繼承AbstractAnnotationConfigDispatcherServletInitializer就可以了,如下代碼所示:

          1. public  
          2.  
          3. class  
          4.  
          5. SugarSpringWebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 
          6.  
          7.     @Override 
          8.     protected Class<?>[] getRootConfigClasses() { 
          9.         return new Class[] { JavaConfig.class }; 
          10.     } 
          11.  
          12.     @Override 
          13.     protected Class<?>[] getServletConfigClasses() { 
          14.         return new Class[] { WebConfig.class }; 
          15.     } 
          16.  
          17.     @Override 
          18.     protected String[] getServletMappings() { 
          19.         return new String[] { "/" }; 
          20.     } 
          21.  

          功能更強(qiáng)大的Spring Test 框架現(xiàn)在,單元測(cè)試顯得越來(lái)越重要了,每一個(gè)類都建議做好對(duì)應(yīng)的單元測(cè)試。在Spring 3.2版本之前,如果要對(duì)Spring MVC進(jìn)行單元測(cè)試的話,必須顯式去調(diào)用某個(gè)控制器類中的某個(gè)方法,而不能直接單元測(cè)試相關(guān)的mapping映射。而在Spring mvc 3.2中,重新整合和增強(qiáng)了測(cè)試框架的功能,支持直接用/*這樣的映射方式去測(cè)試某個(gè)控制器中的類。同時(shí),之前的開(kāi)源項(xiàng)目(https://github.com/SpringSource/spring-test-mvc也被收錄到Spring mvc 3.2中去了。此外,還新增加了對(duì)返回(return),重定向(redirect)model等的測(cè)試改進(jìn),下面是一個(gè)例子:

          1. public class SayHelloControllerIT extends AbstractTestNGSpringContextTests { 
          2.   
          3.     private MockMvc mockMvc; 
          4.   
          5.     @BeforeMethod 
          6.     public void setUp() { 
          7.   
          8.         mockMvc = webAppContextSetup((WebApplicationContext) applicationContext).build(); 
          9.     } 
          10.   
          11.     @Test(dataProvider = "pathParameterAndExpectedModelValue"
          12.     public void accessingSayhelloWithSubpathShouldForwardToSayHelloJspWithModelFilled(String path, String value) throws Exception { 
          13.   
          14.         mockMvc.perform(get("/sayHello/Jo")).andExpect(view().name("sayHello")).andExpect(model().attribute("name""Jo")); 
          15.     } 

          本文的示例代碼可以在: http://blog.frankel.ch/wp-content/resources/spring-3-2-sweetness/spring-sweet-1.0.0.zip中下載。

          原文鏈接:http://java.dzone.com/articles/spring-32-sweetness

          posted @ 2013-07-10 11:48 David1228 閱讀(2352) | 評(píng)論 (0)編輯 收藏
               摘要: 本文轉(zhuǎn)載自:http://www.cnblogs.com/java-my-life/archive/2012/03/28/2418836.html場(chǎng)景問(wèn)題  舉個(gè)生活中常見(jiàn)的例子——組裝電腦,我們?cè)诮M裝電腦的時(shí)候,通常需要選擇一系列的配件,比如CPU、硬盤(pán)、內(nèi)存、主板、電源、機(jī)箱等。為討論使用簡(jiǎn)單點(diǎn),只考慮選擇CPU和主板的問(wèn)題。  事實(shí)上,在選擇CPU的時(shí)候,面臨一系列的...  閱讀全文
          posted @ 2013-07-04 17:07 David1228 閱讀(410) | 評(píng)論 (0)編輯 收藏
          shell中可能經(jīng)常能看到:>/dev/null 2>&1 

          命令的結(jié)果可以通過(guò)%>的形式來(lái)定義輸出

          分解這個(gè)組合:“>/dev/null 2>&1” 為五部分。

          1:> 代表重定向到哪里,例如:echo "123" > /home/123.txt
          2:/dev/null 代表空設(shè)備文件
          3:2> 表示stderr標(biāo)準(zhǔn)錯(cuò)誤
          4:& 表示等同于的意思,2>&1,表示2的輸出重定向等同于1
          5:1 表示stdout標(biāo)準(zhǔn)輸出,系統(tǒng)默認(rèn)值是1,所以">/dev/null"等同于 "1>/dev/null"

          因此,>/dev/null 2>&1 也可以寫(xiě)成“1> /dev/null 2> &1”

          那么本文標(biāo)題的語(yǔ)句執(zhí)行過(guò)程為:
          1>/dev/null :首先表示標(biāo)準(zhǔn)輸出重定向到空設(shè)備文件,也就是不輸出任何信息到終端,說(shuō)白了就是不顯示任何信息。
          2>&1 :接著,標(biāo)準(zhǔn)錯(cuò)誤輸出重定向 到 標(biāo)準(zhǔn)輸出,因?yàn)橹皹?biāo)準(zhǔn)輸出已經(jīng)重定向到了空設(shè)備文件,所以標(biāo)準(zhǔn)錯(cuò)誤輸出也重定向到空設(shè)備文件。

          最常用的方式有:
              
          command > file 2>file  與command > file 2>&1

          它們有什么不同的地方嗎?
                首先command > file 2>file 的意思是將命令所產(chǎn)生的標(biāo)準(zhǔn)輸出信息,和錯(cuò)誤的輸出信息送到file 中.command  > file 2>file 這樣的寫(xiě)法,stdout和stderr都直接送到file中, file會(huì)被打開(kāi)兩次,這樣stdout和stderr會(huì)互相覆蓋,這樣寫(xiě)相當(dāng)使用了FD1和FD2兩個(gè)同時(shí)去搶占file 的管道。
                而command >file 2>&1 這條命令就將stdout直接送向file, stderr 繼承了FD1管道后,再被送往file,此時(shí),file 只被打開(kāi)了一次,也只使用了一個(gè)管道FD1,它包括了stdout和stderr的內(nèi)容。
                從IO效率上,前一條命令的效率要比后面一條的命令效率要低,所以在編寫(xiě)shell腳本的時(shí)候,較多的時(shí)候我們會(huì)command > file 2>&1 這樣的寫(xiě)法。
           
          以上轉(zhuǎn)載自:http://sjolzy.cn/shell-in-the-dev-null-2-gt-amp-1-Detailed.html

          -
          -----------------------------------------------------------------------------------------------------
          那么,有這么個(gè)需求,我如何能判斷遠(yuǎn)程主機(jī)上的某個(gè)文件是否存在呢,我能想到的有兩種方法,一種方法可以使用expect腳本,但是需要遠(yuǎn)程主機(jī)上安裝expect包,但是只需要知道用戶名和密碼就可以了;第二種方法是要求兩臺(tái)主機(jī)之間做好ssh互信,然后如admin,那么通過(guò)shell可以直接判斷,但是文件宿主權(quán)限也需要是admin用戶下的。
          第二種方法腳本如下:
          #!/bin/bash

          ssh dst_host sh -s 2>&1 1>/dev/null <<EOF
          ls $NEW_DST_DIR
          EOF
          IS_EXIST=$?
          if [ "$IS_EXIST"x = "0"x ]; then
             echo "-The file exists------------------------------"
          else
             echo "No file-------------------------------"
          fi

          --大衛(wèi)





          posted @ 2013-07-02 14:45 David1228 閱讀(969) | 評(píng)論 (0)編輯 收藏
          OpenNebula中主機(jī)添加一切正常。
          執(zhí)行$onehost list 主機(jī)CPU、內(nèi)存資源可以正常被監(jiān)控到。但是,創(chuàng)建虛擬機(jī)后,虛擬機(jī)狀態(tài)很長(zhǎng)一段時(shí)間一直處于pend狀態(tài)。而OpenNebula的mm_sched調(diào)度虛擬機(jī)的周期是缺省30秒調(diào)度一次,根據(jù)調(diào)度算法適配一臺(tái)合適的主機(jī),主機(jī)是新添加的而且是有足夠資源的,為什么不能部署呢?
          我們可以通過(guò)查看虛擬機(jī)的調(diào)度日志$ONE_LOCATION/var/sched.log發(fā)現(xiàn)如下錯(cuò)誤信息:
          Tue Feb 21 [HOST][E]: Exception raised: Unable to transport XML to server and get XML response back.
           HTTP response: 504 Tue Feb 22 14:27:39 2011 [POOL][E]: Could not retrieve pool info from ONE。
          解決方法:
          在OpenNebula官方的Wiki中可以找到原因,原因是所添加的主機(jī)使用了HTTP代理上網(wǎng)了,所以O(shè)penNebula讀取了系統(tǒng)的http_proxy環(huán)境變量,此時(shí)就需要關(guān)閉http_proxy。

          I can create VMs, but sched.log shows the error "Could not retrieve pool info from ONE". What's wrong?

          If the scheduler does not deploy the pending VMs, and messages like these are found in sched.log

          [HOST][E]: Exception raised: Unable to transport XML to server and get XML response back.  HTTP response code is 404, not 200 [POOL][E]: Could not retrieve pool info from ONE

          Then you need to unset the http_proxy environment variable, or set the no_proxy accordingly.

          wiki參考地址(這里匯總了使用或部署one過(guò)程中可能遇到的問(wèn)題以及解決辦法):http://wiki.opennebula.org/faq#listing_vms_takes_a_lot_of_time_why

          大家對(duì)于Opennebula的安裝部署感興趣的話,可以參考vpsee的博客(在Centos上安裝和部署Opennebula),講解的很詳細(xì)。

          vpsee已經(jīng)試玩了下OpenNebula4.0,由于項(xiàng)目原因,目前我們還在用OpenNebula3.8.1,后面也會(huì)測(cè)試升級(jí)到OpenNebula4.0看看新功能。
          升級(jí)過(guò)程同樣也參考下vpsee的OpenNebula3.x升級(jí)到OpenNebula4.0,^^ 這么好的資源優(yōu)先借鑒。

          posted @ 2013-06-24 18:01 David1228 閱讀(1091) | 評(píng)論 (0)編輯 收藏
          啟動(dòng)和停止OpenNebula shell腳本如下:
          給這個(gè)腳本起個(gè)名字吧,叫做oned

          #!/bin/bash
          #
          # chkconfig: 345 80 15
          # description: Startup script for the one .

          # Source function library.

          . /etc/rc.d/init.d/functions

          APP_USER=oneadmin
          APP_HOME=/opt/nebula/ONE/

          RETVAL=0

          start(){
                  checkrun
                  if [ $RETVAL -eq 1 ]; then
                          echo "Starting oned"
                          su - $APP_USER -c "$APP_HOME/bin/one start"
              else
                 echo "oned is already running."

                  fi
          }

          stop(){
                  su - $APP_USER -c "$APP_HOME/bin/oneuser list" > /dev/null 2>&1
                  result=$?
                  if [ $result -eq 0 ]; then

                          echo "Shutting down oned"
                          su - $APP_USER -c "$APP_HOME/bin/one stop"

                  elif [ $result -eq 255 ]; then

                          echo "Shutting down oned"
                          pkill -9 -u oneadmin

              fi
          }
             
          checkrun(){
                  su - $APP_USER -c "$APP_HOME/bin/oneuser list" > /dev/null 2>&1
                  if [ $? -eq 0 ]; then
                       RETVAL=0
                       return $RETVAL
              else
                       RETVAL=1
                       return $RETVAL
                  fi
          }

          status(){
                  checkrun
                  if [ $RETVAL -eq 0 ]; then
                          echo "oned is running."
                  else
                      echo "oned is stopped."
                      exit 1
                  fi
          }

          case "$1" in
          start)
                  start
                  RETVAL=$?
                  ;;
          stop)
                  stop
                  RETVAL=$?
                  ;;
          restart)
                  stop
                  start
                  RETVAL=$?
                  ;;
          status)
                  status
                  ;;
          *)
                  echo "Usage: $0 {start|stop|restart|status}"
                  esac
          echo $RETVAL
          exit 0
          Linux中如何設(shè)置服務(wù)開(kāi)機(jī)自啟動(dòng),可以參考http://os.51cto.com/art/201301/377515.htm

          1. 首先查看服務(wù)器默認(rèn)的運(yùn)行級(jí)別是多少? 目的是在對(duì)應(yīng)運(yùn)行級(jí)別下建立服務(wù)的軟連接。
           1> 執(zhí)行命令#runlevel
           [root@compute-63-14]# runlevel
           N 3
           2> 查看/etc/inittab
           [root@compute-63-14 tomcat6]# cat /etc/inittab 
           # inittab is only used by upstart for the default runlevel.
           ... ... 
           id:3:initdefault:
           
          2. 將寫(xiě)好的oned腳本拷貝到/etc/init.d/目錄下

          3. 在/etc/rc.d/rc3.d中建立軟鏈接
          cd /etc/init.d/rc.d/rc3.d
          ln -s ../init.d/oned S99oned
          S99oned是其軟鏈接,S開(kāi)頭代表加載時(shí)自啟動(dòng)

          以上已測(cè)試過(guò),沒(méi)有問(wèn)題,同時(shí)有興趣可以試試第二、三種方式。
          posted @ 2013-06-04 11:18 David1228 閱讀(432) | 評(píng)論 (0)編輯 收藏
          VNCServer X 桌面默認(rèn)為 twm, 這時(shí)連接進(jìn)去只能看到終端界面,而看不到遠(yuǎn)程桌面界面。可修改 /root/.vnc/xstartup 文件,將其改為 GNOME KDE 桌面:
          GNOME

          [root @ test vnc-4_1_2-x86_linux] # vi /root/.vnc/xstartup
          #
          /bin/sh
          [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
          xsetroot –solid grey
          vncconfig –iconic &
          xterm –geometry 80x24+10+10 –ls –title “$VNCDESKTOP Desktop” &
          gnome-session &

          KDE:
          [root @ test vnc-4_1_2-x86_linux] # vi /root/.vnc/xstartup
          #
          /bin/sh
          [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
          xsetroot –solid grey
          vncconfig –iconic &
          xterm –geometry 80x24+10+10 –ls –title “$VNCDESKTOP Desktop” &
          startkde &
          修改完畢后須重新啟動(dòng) VNCServer
          [root @ test vnc-4_1_2-x86_linux] # vncserver –kill :1 && vncserver :1
          [root @ test vnc-4_1_2-x86_linux] # vncviewer 192.168.98.32:1
          連接后即可使用 GNOME KDE 桌面啦(就像 WinXP 的遠(yuǎn)程桌面一般),也可以通過(guò) WEB 訪問(wèn),在瀏覽器中輸入http://192.168.0.252:5801 即可,VNC 默認(rèn)的端口號(hào)為5801

          轉(zhuǎn)載:http://shaoruisky.blog.163.com/blog/static/92610707201151224518579/
          posted @ 2013-03-24 13:07 David1228 閱讀(2841) | 評(píng)論 (0)編輯 收藏
          Spring2.5繼續(xù)堅(jiān)持了這個(gè)發(fā)展趨向,特別是為那些使用Java 5或更新版本java的開(kāi)發(fā)人員提供了進(jìn)一步簡(jiǎn)化而強(qiáng)大的新特性。這些新特性包括:注解驅(qū)動(dòng)的依賴性注入(annotation-driven dependency injection),使用注解而非XML元數(shù)據(jù)來(lái)自動(dòng)偵測(cè)classpath上的Spring組件,注解對(duì)生命周期方法的支持,一個(gè)新的web控制器模型將請(qǐng)求映射到加注解的方法上,在測(cè)試框架中支持Junit4,Spring XML命名空間的新增內(nèi)容,等等。
          項(xiàng)目中使用的spring2.5版本。如果想要使用spring提供的注解功能.
          applicationContext.xml配置文件中增加如下配置:
          <?xml version="1.0" encoding="UTF-8"?>
          <beans xmlns="http://www.springframework.org/schema/beans"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:context="http://www.springframework.org/schema/context"
          xsi:schemaLocation="http://www.springframework.org/schema/beans 
          http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
          http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context-2.5.xsd">
          <!-- Using annontations -->
          <context:annotation-config></context:annotation-config>
          新增以下三項(xiàng)才可以使用注解功能
          xmlns:context="http://www.springframework.org/schema/context"
          http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context-2.5.xsd">
          <context:annotation-config></context:annotation-config>
          或者<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor"/> 注冊(cè)一個(gè)單獨(dú)的Spring post-processor.
          一個(gè)沒(méi)有實(shí)現(xiàn)任何接口的業(yè)務(wù)類,配置如下:
          public class LogService extends Service{
          public LogBiz(){}
          @Resource //默認(rèn)按名稱查找bean. 如果找不到,則按類型匹配bean.
          private BaseDao dao;
          }
          tomcat啟動(dòng)錯(cuò)誤1:
          Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'logBiz': Injection of resource fields failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.ccms.base.dao.BaseDAO] is defined: expected single matching bean but found 40: [baseDAO, loginDAO, logDAO]
          at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessAfterInstantiation(CommonAnnotationBeanPostProcessor.java:291)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:876)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:437)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:383)
          at java.security.AccessController.doPrivileged(Native Method)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:353)
          at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
          at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:169)
          at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
          at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
          at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269)
          ... 32 more
          Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.ccms.base.dao.BaseDAO] is defined: expected single matching bean but found 40: [baseDAO, loginDAO, logDAO]
          at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:583)
          at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:418)
          at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:497)
          at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:145)
          at org.springframework.beans.factory.annotation.InjectionMetadata.injectFields(InjectionMetadata.java:79)
          at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessAfterInstantiation(CommonAnnotationBeanPostProcessor.java:288)
          ... 42 more
          使用@Resource默認(rèn)按名稱查找bean. 如果找不到,則按類型匹配bean.而名稱dao沒(méi)有找到,所以會(huì)根據(jù)BaseDAO匹配,但是BaseDAO是一個(gè)接口:
          <bean id="loginDAO" class="com.test.dao.loginDAO" parent="baseDAO" />
          <bean id="logDAO" class="com.test.dao.logDAO" parent="baseDAO" />
          <bean id="baseDAO" class="com.ccms.base.dao.BaseDAOImpl">
          <property name="sessionFactory">
          <ref bean="sessionFactory" />
          </property>
          <property name="simpleJdbcTemplate">
          <ref bean="simpleJdbcTemplate" />
          </property>
          </bean>
          有兩個(gè)實(shí)現(xiàn)了BaseDAO接口的類,所以spring就不知道應(yīng)該使用哪一個(gè)了。直接拋出異常。
          解決方法1:
          我們可以看到baseDAO名稱是唯一的, 所以如果想要按照名稱匹配,則直接寫(xiě)baseDAO就可以了
          @Resource
          private BaseDAO baseDAO;
          解決方法2:
          @Autowired //默認(rèn)按照類型匹配,同樣應(yīng)為有兩個(gè)子類bean,所以拋出異常。
          @Qualifier("loginDAO") //限定bean
          private BaseDAO dao;
          參考博客:
          http://doc.chinaunix.net/java/200801/240056.shtml
          http://stackoverflow.com/questions/10534053/autowiring-two-beans-implementing-same-interface-how-to-set-default-bean-to-au
          posted @ 2013-03-21 10:22 David1228 閱讀(2504) | 評(píng)論 (0)編輯 收藏
               摘要: jdk并發(fā)部分,如果英文理解有點(diǎn)小難,可以參考http://www.yiibai.com/java6/java/util/concurrent/package-summary.html本篇轉(zhuǎn)自:http://victorzhzh.iteye.com/blog/1011635很多時(shí)候我們希望任務(wù)可以定時(shí)的周期性的執(zhí)行,在最初的JAVA工具類庫(kù)中,通過(guò)Timer可以實(shí)現(xiàn)定時(shí)的周期性的需求,但是有一定的...  閱讀全文
          posted @ 2013-03-18 18:58 David1228 閱讀(1779) | 評(píng)論 (0)編輯 收藏
          使用開(kāi)源云工具OpenNebula3.8.1在KVM環(huán)境下虛擬機(jī)遷移失敗問(wèn)題解決。
          1、虛擬機(jī)遷移失敗1日志:
          Fri Mar  8 17:57:18 2013 [LCM][I]: New VM state is SAVE_MIGRATE
          Fri Mar  8 17:57:30 2013 [VMM][I]: ExitCode: 0
          Fri Mar  8 17:57:30 2013 [VMM][I]: Successfully execute virtualization driver operation: save.
          Fri Mar  8 17:57:30 2013 [VMM][I]: ExitCode: 0
          Fri Mar  8 17:57:30 2013 [VMM][I]: Successfully execute network driver operation: clean.
          Fri Mar  8 17:58:14 2013 [LCM][I]: New VM state is PROLOG_MIGRATE
          Fri Mar  8 17:58:14 2013 [TM][I]: mv: -------------------------/one_images_3.8.1/0/42/disk.0
          Fri Mar  8 17:58:14 2013 [TM][I]: ExitCode: 0
          Fri Mar  8 18:02:28 2013 [TM][I]: mv: Moving bcec162:/one_images_3.8.1/0/42 to node153:/one_images_3.8.1/0/42
          Fri Mar  8 18:02:28 2013 [TM][I]: ExitCode: 0
          Fri Mar  8 18:02:29 2013 [LCM][I]: New VM state is BOOT
          Fri Mar  8 18:02:30 2013 [VMM][I]: ExitCode: 0
          Fri Mar  8 18:02:30 2013 [VMM][I]: Successfully execute network driver operation: pre.
          Fri Mar  8 18:02:33 2013 [VMM][I]: Command execution fail: /var/tmp/one/vmm/kvm/restore /one_images_3.8.1/0/42/checkpoint node153 42 node153
          Fri Mar  8 18:02:33 2013 [VMM][E]: restore: Command "virsh --connect qemu:///system restore /one_images_3.8.1/0/42/checkpoint" failed: error: Failed to restore domain from /one_images_3.8.1/0/42/checkpoint
          Fri Mar  8 18:02:33 2013 [VMM][I]: error: unable to set user and group to '0:0' on '/one_images_3.8.1/0/42/disk.1': No such file or directory
          Fri Mar  8 18:02:33 2013 [VMM][E]: Could not restore from /one_images_3.8.1/0/42/checkpoint
          Fri Mar  8 18:02:33 2013 [VMM][I]: ExitCode: 1
          Fri Mar  8 18:02:33 2013 [VMM][I]: Failed to execute virtualization driver operation: restore.
          Fri Mar  8 18:02:33 2013 [VMM][E]: Error restoring VM: Could not restore from /one_images_3.8.1/0/42/checkpoint
          Fri Mar  8 18:02:34 2013 [DiM][I]: New VM state is FAILED
          Sat Mar  9 09:23:46 2013 [DiM][I]: New VM state is DONE.
          Sat Mar  9 09:23:46 2013 [TM][W]: Ignored: LOG I 42 ExitCode: 0
          Sat Mar  9 09:23:47 2013 [TM][W]: Ignored: LOG I 42 delete: Deleting /one_images_3.8.1/0/42
          Sat Mar  9 09:23:47 2013 [TM][W]: Ignored: LOG I 42 ExitCode: 0
          Sat Mar  9 09:23:47 2013 [TM][W]: Ignored: TRANSFER SUCCESS 42 -
          解決方法:
          在mv腳本中TAR拷貝命令前面增加$SUDO命令.
          $ONE_LOCATION/var/remotes/tm/ssh/mv
          #!/bin/bash
          # -------------------------------------------------------------------------- #
          # Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org)             #
          #                                                                            #
          # Licensed under the Apache License, Version 2.0 (the "License"); you may    #
          # not use this file except in compliance with the License. You may obtain    #
          # a copy of the License at                                                   #
          #                                                                            #
          # http://www.apache.org/licenses/LICENSE-2.0                                 #
          #                                                                            #
          # Unless required by applicable law or agreed to in writing, software        #
          # distributed under the License is distributed on an "AS IS" BASIS,          #
          # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
          # See the License for the specific language governing permissions and        #
          # limitations under the License.                                             #
          #--------------------------------------------------------------------------- #
          # MV <hostA:system_ds/disk.i|hostB:system_ds/disk.i> vmid dsid
          #    <hostA:system_ds/|hostB:system_ds/>
          #   - hostX is the target host to deploy the VM
          #   - system_ds is the path for the system datastore in the host
          #   - vmid is the id of the VM
          #   - dsid is the target datastore (0 is the system datastore)
          SRC=$1
          DST=$2
          VMID=$3
          DSID=$4
          if [ -z "${ONE_LOCATION}" ]; then
              TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
          else
              TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
          fi
          . $TMCOMMON
          #-------------------------------------------------------------------------------
          # Return if moving a disk, we will move them when moving the whole system_ds
          # directory for the VM
          #-------------------------------------------------------------------------------
          SRC=`fix_dir_slashes $SRC`
          DST=`fix_dir_slashes $DST`
          SRC_PATH=`arg_path $SRC`
          DST_PATH=`arg_path $DST`
          SRC_HOST=`arg_host $SRC`
          DST_HOST=`arg_host $DST`
          DST_DIR=`dirname $DST_PATH`
          SRC_DS_DIR=`dirname  $SRC_PATH`
          SRC_VM_DIR=`basename $SRC_PATH`
          if [ `is_disk $DST_PATH` -eq 1 ]; then
              log "-------------------------$DST_PATH"
          exit 0
          fi
          if [ "$SRC" == "$DST" ]; then
              exit 0
          fi
          ssh_make_path "$DST_HOST" "$DST_DIR"
          log "Moving $SRC to $DST"
          ssh_exec_and_log "$DST_HOST" "rm -rf '$DST_PATH'" \
              "Error removing target path to prevent overwrite errors"
          TAR_COPY="$SSH $SRC_HOST '$SUDO $TAR -C $SRC_DS_DIR -cf - $SRC_VM_DIR'"
          TAR_COPY="$TAR_COPY | $SSH $DST_HOST '$TAR -C $DST_DIR -xf -'"
          exec_and_log "eval $TAR_COPY" "Error copying disk directory to target host"
          exec_and_log "$SSH $SRC_HOST rm -rf $SRC_PATH"
          exit 0
          -------------------------------------------------------------------------------------------
          2、虛擬機(jī)遷移失敗2日志:
          Sat Mar  9 09:34:12 2013 [LCM][I]: New VM state is SAVE_MIGRATE
          Sat Mar  9 09:34:24 2013 [VMM][I]: ExitCode: 0
          Sat Mar  9 09:34:24 2013 [VMM][I]: Successfully execute virtualization driver operation: save.
          Sat Mar  9 09:34:24 2013 [VMM][I]: ExitCode: 0
          Sat Mar  9 09:34:24 2013 [VMM][I]: Successfully execute network driver operation: clean.
          Sat Mar  9 09:34:25 2013 [LCM][I]: New VM state is PROLOG_MIGRATE
          Sat Mar  9 09:34:25 2013 [TM][I]: mv: -------------------------/one_images_3.8.1/0/43/disk.0
          Sat Mar  9 09:34:25 2013 [TM][I]: ExitCode: 0
          Sat Mar  9 09:36:38 2013 [TM][I]: mv: Moving node153:/one_images_3.8.1/0/43 to bcec162:/one_images_3.8.1/0/43
          Sat Mar  9 09:36:38 2013 [TM][I]: mv: -------------------target copyy
          Sat Mar  9 09:36:38 2013 [TM][I]: mv: ++++++++++++++++++++++end copy
          Sat Mar  9 09:36:38 2013 [TM][I]: ExitCode: 0
          Sat Mar  9 09:36:38 2013 [LCM][I]: New VM state is BOOT
          Sat Mar  9 09:36:38 2013 [VMM][I]: ExitCode: 0
          Sat Mar  9 09:36:38 2013 [VMM][I]: Successfully execute network driver operation: pre.
          Sat Mar  9 09:36:42 2013 [VMM][I]: Command execution fail: /var/tmp/one/vmm/kvm/restore /one_images_3.8.1/0/43/checkpoint bcec162 43 bcec162
          Sat Mar  9 09:36:42 2013 [VMM][E]: restore: Command "virsh --connect qemu:///system restore /one_images_3.8.1/0/43/checkpoint" failed: error: Failed to restore domain from /one_images_3.8.1/0/43/checkpoint
          Sat Mar  9 09:36:42 2013 [VMM][I]: error: internal error process exited while connecting to monitor: Supported machines are:
          Sat Mar  9 09:36:42 2013 [VMM][I]: pc         RHEL 6.0.0 PC (alias of rhel6.0.0)
          Sat Mar  9 09:36:42 2013 [VMM][I]: rhel6.0.0  RHEL 6.0.0 PC (default)
          Sat Mar  9 09:36:42 2013 [VMM][I]: rhel5.5.0  RHEL 5.5.0 PC
          Sat Mar  9 09:36:42 2013 [VMM][I]: rhel5.4.4  RHEL 5.4.4 PC
          Sat Mar  9 09:36:42 2013 [VMM][I]: rhel5.4.0  RHEL 5.4.0 PC
          Sat Mar  9 09:36:42 2013 [VMM][E]: Could not restore from /one_images_3.8.1/0/43/checkpoint
          Sat Mar  9 09:36:42 2013 [VMM][I]: ExitCode: 1
          Sat Mar  9 09:36:42 2013 [VMM][I]: Failed to execute virtualization driver operation: restore.
          Sat Mar  9 09:36:42 2013 [VMM][E]: Error restoring VM: Could not restore from /one_images_3.8.1/0/43/checkpoint
          Sat Mar  9 09:36:42 2013 [DiM][I]: New VM state is FAILED
          登陸到節(jié)點(diǎn):
          [root@bcec162 43]# virsh restore checkpoint 
          錯(cuò)誤:從 checkpoint 恢復(fù)域失敗
          錯(cuò)誤:internal error process exited while connecting to monitor: Supported machines are:
          pc         RHEL 6.0.0 PC (alias of rhel6.0.0)
          rhel6.0.0  RHEL 6.0.0 PC (default)
          rhel5.5.0  RHEL 5.5.0 PC
          rhel5.4.4  RHEL 5.4.4 PC
          rhel5.4.0  RHEL 5.4.0 PC
          修改了bcec162節(jié)點(diǎn)的/etc/libvirt/qemu.conf文件:
          # The user ID for QEMU processes run by the system instance
          user = "root"
          # The group ID for QEMU processes run by the system instance
          group = "root"
          # Whether libvirt should dynamically change file ownership
          # to match the configured user/group above. Defaults to 1.
          # Set to 0 to disable file ownership changes.
          #dynamic_ownership = 0
          bcec162節(jié)點(diǎn)遷移到node153節(jié)點(diǎn)成功。
          [root@node153 43]# ll
          total 5075464
          -rw-r--r-- 1 root     root  287215779 Mar  8 11:11 checkpoint
          -rw-r--r-- 1 oneadmin kvm   283538737 Mar  9 09:34 checkpoint.1362712278
          -rw-r--r-- 1 oneadmin kvm         920 Mar  9 09:26 deployment.0
          -rw-r--r-- 1 root     root 4621008896 Mar  9 10:14 disk.0
          -rw-r----- 1 root     root     401408 Mar  9 09:26 disk.1
          lrwxrwxrwx 1 oneadmin kvm          29 Mar  9 10:09 disk.1.iso -> /one_images_3.8.1/0/43/disk.1
          --------------------------------------------------------------------------------------------------------
          3、僅修改node152節(jié)點(diǎn)的/etc/libvirt/qemu.conf文件:
          # The user ID for QEMU processes run by the system instance
          #user = "root"
          # The group ID for QEMU processes run by the system instance
          #group = "root"
          # Whether libvirt should dynamically change file ownership
          # to match the configured user/group above. Defaults to 1.
          # Set to 0 to disable file ownership changes.
          dynamic_ownership = 0
          從bcec162節(jié)點(diǎn)遷移到node152不成功,日志如下:
          Sat Mar  9 10:31:47 2013 [LCM][I]: New VM state is SAVE_MIGRATE
          Sat Mar  9 10:31:54 2013 [VMM][I]: save: Moving old checkpoint file /one_images_3.8.1/0/43/checkpoint
          Sat Mar  9 10:31:54 2013 [VMM][I]: ExitCode: 0
          Sat Mar  9 10:31:54 2013 [VMM][I]: Successfully execute virtualization driver operation: save.
          Sat Mar  9 10:31:54 2013 [VMM][I]: ExitCode: 0
          Sat Mar  9 10:31:54 2013 [VMM][I]: Successfully execute network driver operation: clean.
          Sat Mar  9 10:31:55 2013 [LCM][I]: New VM state is PROLOG_MIGRATE
          Sat Mar  9 10:31:55 2013 [TM][I]: mv: -------------------------/one_images_3.8.1/0/43/disk.0
          Sat Mar  9 10:31:55 2013 [TM][I]: ExitCode: 0
          Sat Mar  9 10:35:02 2013 [TM][I]: mv: Moving bcec162:/one_images_3.8.1/0/43 to node152:/one_images_3.8.1/0/43
          Sat Mar  9 10:35:02 2013 [TM][I]: mv: -------------------target copyy
          Sat Mar  9 10:35:02 2013 [TM][I]: mv: ++++++++++++++++++++++end copy
          Sat Mar  9 10:35:02 2013 [TM][I]: ExitCode: 0
          Sat Mar  9 10:35:02 2013 [LCM][I]: New VM state is BOOT
          Sat Mar  9 10:35:03 2013 [VMM][I]: ExitCode: 0
          Sat Mar  9 10:35:03 2013 [VMM][I]: Successfully execute network driver operation: pre.
          Sat Mar  9 10:35:07 2013 [VMM][I]: Command execution fail: /var/tmp/one/vmm/kvm/restore /one_images_3.8.1/0/43/checkpoint node152 43 node152
          Sat Mar  9 10:35:07 2013 [VMM][E]: restore: Command "virsh --connect qemu:///system restore /one_images_3.8.1/0/43/checkpoint" failed: error: Failed to restore domain from /one_images_3.8.1/0/43/checkpoint
          Sat Mar  9 10:35:07 2013 [VMM][I]: error: operation failed: failed to retrieve chardev info in qemu with 'info chardev'
          Sat Mar  9 10:35:07 2013 [VMM][E]: Could not restore from /one_images_3.8.1/0/43/checkpoint
          Sat Mar  9 10:35:07 2013 [VMM][I]: ExitCode: 1
          Sat Mar  9 10:35:07 2013 [VMM][I]: Failed to execute virtualization driver operation: restore.
          Sat Mar  9 10:35:07 2013 [VMM][E]: Error restoring VM: Could not restore from /one_images_3.8.1/0/43/checkpoint
          Sat Mar  9 10:35:07 2013 [DiM][I]: New VM state is FAILED
          登陸到node152節(jié)點(diǎn)執(zhí)行restore命令:
          [root@node152 43]# virsh restore checkpoint
          error: Failed to restore domain from checkpoint
          error: internal error process exited while connecting to monitor: qemu: could not open disk image /one_images_3.8.1/0/43/disk.0: Permission denied
          將/etc/libvirt/qemu.conf文件中注釋掉dynamic_ownership=0,開(kāi)啟user=root和group=root. 
          如果開(kāi)啟dynamic_ownership則恢復(fù)虛擬機(jī)也會(huì)報(bào)出上面的錯(cuò)誤信息。
          在node152節(jié)點(diǎn)上恢復(fù)虛擬機(jī):
          [root@node152 43]# virsh restore checkpoint
          Domain restored from checkpoint
          [root@node152 43]# virsh list
           Id Name                 State
          ----------------------------------
          117 one-43               running
          參考文章:
          https://wiki.archlinux.org/index.php/QEMU_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)
          http://hi.baidu.com/juacm/item/f1fc3f98d8428ad07a7f01e2

          轉(zhuǎn)載請(qǐng)保持原鏈接:http://www.aygfsteel.com/ldwblog/archive/2013/03/08/396187.html
          posted @ 2013-03-08 12:03 David1228 閱讀(768) | 評(píng)論 (0)編輯 收藏
          項(xiàng)目組內(nèi)一位同事,在重構(gòu)代碼過(guò)程中將幾個(gè)模塊的Service層接口去掉后. 修改成了沒(méi)有實(shí)現(xiàn)任何接口的類,并且繼承了一個(gè)抽象基類。
          然后我更新代碼后執(zhí)行系統(tǒng)中的該模塊,發(fā)現(xiàn)部分表數(shù)據(jù)沒(méi)有完整持久到數(shù)據(jù)庫(kù)中。看了下代碼和spring配置文件,原來(lái)調(diào)整后的Biz的業(yè)務(wù)類沒(méi)有配置事務(wù)導(dǎo)致的。
          修改了下spring配置文件(beanNames綁定了*Biz):
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
              <bean id= "propertyConfigurer"          
                  class 
          = "com.ccms.base.util.DecryptPropertyPlaceholderConfigurer" >          
               <property name="locations" value= "classpath:sysConfig.properties" />          
             </bean>      
              <!-- 
             <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
                  destroy-method="close">
                  <property name="driverClassName">
                      <value>com.mysql.jdbc.Driver</value>
                  </property>
                  <property name="url">
                      <value>${dataSource.jdbcUrl}&amp;useUnicode=true&amp;characterEncoding=UTF-8</value>
                  </property>
                  <property name="username">
                      <value>${dataSource.userName}</value>
                  </property>
                  <property name="password">
                      <value>${dataSource.password}</value>
                  </property>
                  <property name="maxActive">
                      <value>100</value>
                  </property>
                  <property name="initialSize">
                      <value>5</value>
                  </property>
                  <property name="maxIdle">
                      <value>10</value>
                  </property>
                  <property name="minIdle">
                      <value>0</value>
                  </property>
                  <property name="maxWait">
                      <value>-1</value>
                  </property>
                  <property name="defaultAutoCommit">
                      <value>false</value>
                  </property>
                  <property name="testOnBorrow">
                      <value>true</value>
                  </property>
                  <property name="testWhileIdle">
                      <value>true</value>
                  </property>
                  <property name="timeBetweenEvictionRunsMillis">
                      <value>600000</value>
                  </property>
                  <property name="numTestsPerEvictionRun">
                      <value>20</value>
                  </property>
                  <property name="minEvictableIdleTimeMillis">
                      <value>3600000</value>
                  </property>
              </bean>
             
          -->
              <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close" >
                  <property name="driverClass" value="com.mysql.jdbc.Driver" />
                  <property name="jdbcUrl" value="${dataSource.jdbcUrl}&amp;useUnicode=true&amp;characterEncoding=UTF-8" />
                  <property name="user" value="${dataSource.userName}" />
                  <property name="password" value="${dataSource.password}" />
                    <property name="minPoolSize" value="5" />
                  <property name="maxPoolSize" value="50" />
                  <property name="maxStatements" value="0" />
                  <property name="idleConnectionTestPeriod" value="60" />
                  <property name="acquireRetryAttempts" value="3" />
              </bean>

              <!-- Session Factory -->
              <bean id="sessionFactory"
                  class
          ="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
                  <property name="dataSource">
                      <ref local="dataSource" />
                  </property>
              <!-- hbm配置文件的classPath路徑 -->
                  <property name="mappingDirectoryLocations">
                      <list>
                          <value>classpath:/com/ccms/base/mapping</value>
                      </list>
                  </property>

                  <property name="hibernateProperties">
                      <props>
                          <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                          <prop key="hibernate.show_sql">true</prop>
                          <prop key="hibernate.generate_statistics">true</prop>
                          <prop key="hibernate.connection.release_mode">auto</prop>
                          <prop key="hibernate.autoReconnect">true</prop> 
                          <prop key="hibernate.connection.autocommit">false</prop>
                          <!-- <prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</prop> -->
                      </props>
                  </property>
              </bean>

              <bean id="myTransactionManager"
                  class
          ="org.springframework.orm.hibernate3.HibernateTransactionManager">
                  <property name="sessionFactory">
                      <ref bean="sessionFactory" />
                  </property>
              </bean> 

              <bean id="transactionInterceptor"
                  class
          ="org.springframework.transaction.interceptor.TransactionInterceptor">
                  <property name="transactionManager" ref="myTransactionManager" />
                  <property name="transactionAttributes">
                      <props>
                          <prop key="*">PROPAGATION_REQUIRED,-Exception</prop>
                      </props>
                  </property>
              </bean>
              <bean  class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
                  <property name="transactionInterceptor"
                      ref
          ="transactionInterceptor" />
              </bean>
              <bean
                  
          class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
                  <property name="beanNames">
                      <list>
                          <value>*Service</value>
                          <value>*Biz</value>
                      </list>
                  </property>
                  <property name="interceptorNames">
                      <list>
                          <value>transactionInterceptor</value>
                      </list>
                  </property>
              </bean>
          </beans>

          啟動(dòng)tomcat后報(bào)出如下錯(cuò)誤信息:
          [2013-03-05 10:36:56] [ERROR] Context initialization failed - at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:215) 
          org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loginBiz' defined in ServletContext resource [/WEB-INF/spring-service-resource.xml]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.ccms.login.LoginBiz]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:445)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:383)
          at java.security.AccessController.doPrivileged(Native Method)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:353)
          at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
          at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:169)
          at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
          at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
          at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:400)
          at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:736)
          at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:369)
          at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:261)
          at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
          at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
          at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4135)
          at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)
          at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
          at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
          at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
          at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
          at org.apache.catalina.core.StandardService.start(StandardService.java:519)
          at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
          at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:597)
          at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
          at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
          Caused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.ccms.login.LoginBiz]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
          at org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopProxy.java:213)
          at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:110)
          at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:433)
          at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:299)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:331)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1266)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:438)
          ... 28 more
          Caused by: java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
          at net.sf.cglib.proxy.Enhancer.emitConstructors(Enhancer.java:718)
          at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer.java:499)
          at net.sf.cglib.transform.TransformingClassGenerator.generateClass(TransformingClassGenerator.java:33)
          at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
          at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
          at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
          at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:285)
          at org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopProxy.java:201)
          ... 34 more
          2013-3-5 10:36:56 org.apache.catalina.core.StandardContext listenerStart
          嚴(yán)重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
          org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loginBiz' defined in ServletContext resource [/WEB-INF/spring-service-resource.xml]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.ccms.login.LoginBiz]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:445)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:383)
          at java.security.AccessController.doPrivileged(Native Method)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:353)
          at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
          at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:169)
          at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
          at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
          at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:400)
          at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:736)
          at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:369)
          at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:261)
          at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
          at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
          at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4135)
          at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)
          at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
          at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
          at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
          at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
          at org.apache.catalina.core.StandardService.start(StandardService.java:519)
          at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
          at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:597)
          at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
          at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
          Caused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.ccms.login.LoginBiz]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
          at org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopProxy.java:213)
          at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:110)
          at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:433)
          at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:299)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:331)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1266)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:438)
          ... 28 more
          Caused by: java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
          at net.sf.cglib.proxy.Enhancer.emitConstructors(Enhancer.java:718)
          at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer.java:499)
          at net.sf.cglib.transform.TransformingClassGenerator.generateClass(TransformingClassGenerator.java:33)
          at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
          at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
          at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
          at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:285)
          at org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopProxy.java:201)
          ... 34 more
          2013-3-5 10:36:56 org.apache.catalina.core.StandardContext start

          ------------------------------------------
          通過(guò)以上錯(cuò)誤分析之:對(duì)于實(shí)現(xiàn)了接口的類,直接用了JDK的動(dòng)態(tài)代理,把目標(biāo)對(duì)象扔給JDK的Proxy,拿到代理對(duì)象就OK了。然而對(duì)于沒(méi)有實(shí)現(xiàn)接口的類,Spring借助于CGLIB來(lái)實(shí)現(xiàn)代理。
          解決辦法:
          當(dāng)使用CGLIB來(lái)實(shí)現(xiàn)代理后,沒(méi)有實(shí)現(xiàn)接口的類
          1、 通過(guò)構(gòu)造函數(shù)形式注入時(shí)必須有默認(rèn)的構(gòu)造函數(shù),否則就會(huì)出現(xiàn)上面的異常。
          2、通過(guò)生產(chǎn)setter或者getter方法注入。
          3、通過(guò)修改Spring的CglibProxyFactory工廠類。

          詳細(xì)解析可以參照這篇文章:http://netfork.iteye.com/blog/286215
          posted @ 2013-03-05 14:54 David1228 閱讀(10778) | 評(píng)論 (0)編輯 收藏

          Deserializes JavaScript Object Notation (JSON) text to produce a JavaScript value.

          JSON.parse(text [, reviver]) 
          Arguments

          text

          Required. Valid JSON text.

          reviver

          Optional. A function that filters and transforms the results. The deserialized object is traversed recursively, and the reviver function is called for each member of the object in post-order (every object is revived after all its members have been revived). For each member, the following occurs:

          • If reviver returns a valid value, the member value is replaced with the value returned by reviver.

          • If reviver returns what it received, the structure is not modified.

          • If reviver returns null or undefined, the object member is deleted.

          The reviver argument is often used to transform JSON representation of International Organization for Standardization (ISO) date strings into Coordinated Universal Time (UTC) format Date objects.

          Return Value

          A JavaScript value—an object or array.

          Exceptions

          Exception

          Condition

          JavaScript parser errors

          The input text does not comply with JSON syntax. To correct the error, do one of the following:

          • Modify the text argument to comply with JSON syntax. For more information, see the BNF syntax notation of JSON objects.

          • Make sure that the text argument was serialized by a JSON-compliant implementation, such as, JSON.stringify.

          Example

          This example uses JSON.parse to deserialize JSON text into the contact object.

          var jsontext = '{"firstname":"Jesper","surname":"Aaberg","phone":["555-0100","555-0120"]}'; var contact = JSON.parse(jsontext); var fullname = contact.surname + ", " + contact.firstname; // The value of fullname is "Aaberg, Jesper" 

          This example uses JSON.parse to deserialize an ISO-formatted date string. The dateReviver function returns Date objects for members that are formatted like ISO date strings.

          var jsontext = '{ "hiredate": "2008-01-01T12:00:00Z", "birthdate": "2008-12-25T12:00:00Z" }'; var dates = JSON.parse(jsontext, dateReviver); var string = dates.birthdate.toUTCString(); // The value of string is "Thu, 25 Dec 2008 12:00:00 UTC"  function dateReviver(key, value) {     var a;     if (typeof value === 'string') {         a = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);         if (a) {             return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],                             +a[5], +a[6]));         }     }     return value; }; 
          Requirements

          Supported in the following document modes: Internet Explorer 8 standards, Internet Explorer 9 standards. See Version Information.

          Not supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards.

          Serializes a JavaScript value into JavaScript Object Notation (JSON) text.

          JSON.stringify(value [, replacer] [, space]) 
          value

          Required. A JavaScript value, usually an object or array, to be serialized.

          replacer

          Optional. A function or array that filters and transforms the results.

          If replacer is a function, JSON.stringify calls the function, passing in the key and value of each member. The return value is serialized instead of the original value. If the function returns undefined, the member will be excluded from the serialization. The key for the root object is an empty string: "".

          If replacer is an array, only members with key values in the array will be serialized. The order of serialization is the same as the order of the keys in the array. Thereplacer array is ignored when the value argument is also an array.

          space

          Optional. Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.

          If space is omitted, the return-value text is generated without any extra white space.

          If space is a number, the return-value text is indented with the specified number of white spaces at each level. If space is greater than 10, text is indented 10 spaces.

          If space is a non-empty string, such as '\t', the return-value text is indented with the characters in the string at each level.

          If space is a string that is longer than 10 characters, the first 10 characters are used.

          A string that contains the serialized JSON text.

          Exception

          Condition

          Invalid replacer argument

          The replacer argument is not a function or an array.

          Circular reference in value argument not supported

          The value argument contains a circular reference.

          If the value that is being serialized has a toJSON method, the JSON.stringify function calls the toJSON method and uses the return value for serialization. If the return value of the toJSON method is undefined, the member will not be serialized. This enables an object to determine its own JSON representation.

          Values that do not have JSON representations, such as undefined, will not be serialized. In objects, they will be dropped. In arrays, they will be replaced with null.

          String values begin and end with a quotation mark. All Unicode characters may be enclosed in the quotation marks except for the characters that must be escaped by using a backslash. The following characters must be preceded by a backslash:

          • Quotation mark (")

          • Backslash (\)

          • Backspace (b)

          • Formfeed (f)

          • Newline (n)

          • Carriage return (r)

          • Horizontal tab (t)

          • Four-hexadecimal-digits (uhhhh)

          Order of Execution

          During the serialization process, if a toJSON method exists for the value argument, JSON.stringify first calls the toJSON method. If it does not exist, the original value is used. Next, if a replacer argument is provided, the value (original value or toJSON return-value) is replaced with the return-value of the replacer argument. Finally, white spaces are added to the value based on the optional space argument to generate the final serialized JSON text.

          This example uses JSON.stringify to serialize the contact object to JSON text. The memberfilter array is defined so that only the surname and phone members are serialized. The firstname member is omitted.

          var contact = new Object(); contact.firstname = "Jesper"; contact.surname = "Aaberg"; contact.phone = ["555-0100", "555-0120"];  var memberfilter = new Array(); memberfilter[0] = "surname"; memberfilter[1] = "phone"; var jsonText = JSON.stringify(contact, memberfilter, "\t"); /* The value of jsonText is: '{     "surname": "Aaberg",     "phone": [         "555-0100",         "555-0120"     ] }' */ 

          This example uses JSON.stringify to serialize an array. The replaceToUpper function converts every string in the array to uppercase.

          var continents = new Array(); continents[0] = "Europe"; continents[1] = "Asia"; continents[2] = "Australia"; continents[3] = "Antarctica"; continents[4] = "North America"; continents[5] = "South America"; continents[6] = "Africa";  var jsonText = JSON.stringify(continents, replaceToUpper); /* The value of jsonText is: '"EUROPE,ASIA,AUSTRALIA,ANTARCTICA,NORTH AMERICA,SOUTH AMERICA,AFRICA"' */  function replaceToUpper(key, value) {     return value.toString().toUpperCase(); } 

          This example uses the toJSON method to serialize string member values in uppercase.

          var contact = new Object();  contact.firstname = "Jesper"; contact.surname = "Aaberg"; contact.phone = ["555-0100", "555-0120"];  contact.toJSON = function(key)  {     var replacement = new Object();     for (var val in this)     {         if (typeof (this[val]) === 'string')             replacement[val] = this[val].toUpperCase();         else             replacement[val] = this[val]     }     return replacement; };  var jsonText = JSON.stringify(contact);  /* The value of jsonText is: '{"firstname":"JESPER","surname":"AABERG","phone":["555-0100","555-0120"]}' */ 

          Supported in the following document modes: Internet Explorer 8 standards, Internet Explorer 9 standards. See Version Information.

          Not supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards.




          http://msdn.microsoft.com/library/cc836459(VS.85).aspx

          posted @ 2013-03-04 16:59 David1228 閱讀(895) | 評(píng)論 (0)編輯 收藏

          <2013年3月>
          242526272812
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          常用鏈接

          留言簿(4)

          隨筆分類

          隨筆檔案

          文章檔案

          新聞分類

          新聞檔案

          相冊(cè)

          收藏夾

          Java

          Linux知識(shí)相關(guān)

          Spring相關(guān)

          云計(jì)算/Linux/虛擬化技術(shù)/

          友情博客

          多線程并發(fā)編程

          開(kāi)源技術(shù)

          持久層技術(shù)相關(guān)

          搜索

          •  

          積分與排名

          • 積分 - 359879
          • 排名 - 154

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 灵台县| 汶川县| 龙山县| 固安县| 皮山县| 金塔县| 繁峙县| 威宁| 政和县| 梁山县| 麻栗坡县| 长海县| 宿州市| 北碚区| 古浪县| 屏边| 惠来县| 文登市| 那坡县| 繁昌县| 阿荣旗| 轮台县| 高安市| 肃南| 武汉市| 托克托县| 西畴县| 海盐县| 特克斯县| 衢州市| 贵定县| 惠东县| 新巴尔虎右旗| 济阳县| 剑阁县| 时尚| 新竹县| 七台河市| 克什克腾旗| 新泰市| 金华市|