posts - 167,  comments - 30,  trackbacks - 0

不得不承认的是,在目前的web应用开发中,Spring的应用越来越广泛,其地位变得相当重要。而在最近推出的Spring 3.2版本中,又引入了一些新的值得关注的特性。本文中将介绍其中一些值得关注的新特性。

一 不再需要web.xml

 在新的Spring 3.2中,可以不再需要web.xml这个文件了,这得益于Servlet 3.0的新特性。

其中,可以使用@WebServlet在需要调用的servlet中,使用注解去设置servlet中的映射关系。这样的话,就可以不再象以往那样要通过在web.xml中对servlet进行配置,十分方便。

此外,Servlet 3.0提供了既能在容器中动态注册servlet的方法,也提供了通过实现

ServletContainerInitializer接口的方法实现在容器启动阶段为容器动态注册Servlet、Filter和listeners。容器会在应用的启动阶段,调用所有实现ServletContainerInitializer接口类中的onStartup()方法。而Spring 3.2中,则进一步简化了这点,只需要实现WebApplicationInitializer接口就可以了,其中提供了一个相关的实现类--AbstractContextLoaderInitializer,它可以动态注册DispatcherServlet。这意味着,只要spring-webmvc.jar放置在web应用的web-inf/lib中,就可以调用Dispatcher servlet了。可以参考如下的例子(来自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中,一个不错的特性就是在之前版本中支持使用Java代码配置各种依赖注入的基础上,进一步简化了配置。关于使用Java编程式配置的好处,可以通过下面这个链接文章的介绍去学习

http://blog.frankel.ch/consider-replacing-spring-xml-configuration-with-javaconfig)。
在Spring mvc 3.2中,提供了AbstractContextLoaderInitialize的一个子类AbstractAnnotationConfigDispatcherServletInitializer去实现零XML配置的效果,只需要创建的类继承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.  

功能更强大的Spring Test 框架现在,单元测试显得越来越重要了,每一个类都建议做好对应的单元测试。在Spring 3.2版本之前,如果要对Spring MVC进行单元测试的话,必须显式去调用某个控制器类中的某个方法,而不能直接单元测试相关的mapping映射。而在Spring mvc 3.2中,重新整合和增强了测试框架的功能,支持直接用/*这样的映射方式去测试某个控制器中的类。同时,之前的开源项目(https://github.com/SpringSource/spring-test-mvc也被收录到Spring mvc 3.2中去了。此外,还新增加了对返回(return),重定向(redirect)model等的测试改进,下面是一个例子:

  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 阅读(2337) | 评论 (0)编辑 收藏
     摘要: 本文转载自:http://www.cnblogs.com/java-my-life/archive/2012/03/28/2418836.html场景问题  举个生活中常见的例子——组装电脑,我们在组装电脑的时候,通常需要选择一系列的配件,比如CPU、硬盘、内存、主板、电源、机箱等。为讨论使用简单点,只考虑选择CPU和主板的问题。  事实上,在选择CPU的时候,面临一系列的...  阅读全文
posted @ 2013-07-04 17:07 David1228 阅读(392) | 评论 (0)编辑 收藏
shell中可能经常能看到:>/dev/null 2>&1 

命令的结果可以通过%>的形式来定义输出

分解这个组合:“>/dev/null 2>&1” 为五部分。

1:> 代表重定向到哪里,例如:echo "123" > /home/123.txt
2:/dev/null 代表空设备文件
3:2> 表示stderr标准错误
4:& 表示等同于的意思,2>&1,表示2的输出重定向等同于1
5:1 表示stdout标准输出,系统默认值是1,所以">/dev/null"等同于 "1>/dev/null"

因此,>/dev/null 2>&1 也可以写成“1> /dev/null 2> &1”

那么本文标题的语句执行过程为:
1>/dev/null :首先表示标准输出重定向到空设备文件,也就是不输出任何信息到终端,说白了就是不显示任何信息。
2>&1 :接着,标准错误输出重定向 到 标准输出,因为之前标准输出已经重定向到了空设备文件,所以标准错误输出也重定向到空设备文件。

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

它们有什么不同的地方吗?
      首先command > file 2>file 的意思是将命令所产生的标准输出信息,和错误的输出信息送到file 中.command  > file 2>file 这样的写法,stdout和stderr都直接送到file中, file会被打开两次,这样stdout和stderr会互相覆盖,这样写相当使用了FD1和FD2两个同时去抢占file 的管道。
      而command >file 2>&1 这条命令就将stdout直接送向file, stderr 继承了FD1管道后,再被送往file,此时,file 只被打开了一次,也只使用了一个管道FD1,它包括了stdout和stderr的内容。
      从IO效率上,前一条命令的效率要比后面一条的命令效率要低,所以在编写shell脚本的时候,较多的时候我们会command > file 2>&1 这样的写法。
 
以上转载自:http://sjolzy.cn/shell-in-the-dev-null-2-gt-amp-1-Detailed.html

-
-----------------------------------------------------------------------------------------------------
那么,有这么个需求,我如何能判断远程主机上的某个文件是否存在呢,我能想到的有两种方法,一种方法可以使用expect脚本,但是需要远程主机上安装expect包,但是只需要知道用户名和密码就可以了;第二种方法是要求两台主机之间做好ssh互信,然后如admin,那么通过shell可以直接判断,但是文件宿主权限也需要是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

--大卫





posted @ 2013-07-02 14:45 David1228 阅读(947) | 评论 (0)编辑 收藏
OpenNebula中主机添加一切正常。
执行$onehost list 主机CPU、内存资源可以正常被监控到。但是,创建虚拟机后,虚拟机状态很长一段时间一直处于pend状态。而OpenNebula的mm_sched调度虚拟机的周期是缺省30秒调度一次,根据调度算法适配一台合适的主机,主机是新添加的而且是有足够资源的,为什么不能部署呢?
我们可以通过查看虚拟机的调度日志$ONE_LOCATION/var/sched.log发现如下错误信息:
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中可以找到原因,原因是所添加的主机使用了HTTP代理上网了,所以OpenNebula读取了系统的http_proxy环境变量,此时就需要关闭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过程中可能遇到的问题以及解决办法):http://wiki.opennebula.org/faq#listing_vms_takes_a_lot_of_time_why

大家对于Opennebula的安装部署感兴趣的话,可以参考vpsee的博客(在Centos上安装和部署Opennebula),讲解的很详细。

vpsee已经试玩了下OpenNebula4.0,由于项目原因,目前我们还在用OpenNebula3.8.1,后面也会测试升级到OpenNebula4.0看看新功能。
升级过程同样也参考下vpsee的OpenNebula3.x升级到OpenNebula4.0,^^ 这么好的资源优先借鉴。

posted @ 2013-06-24 18:01 David1228 阅读(1066) | 评论 (0)编辑 收藏
启动和停止OpenNebula shell脚本如下:
给这个脚本起个名字吧,叫做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中如何设置服务开机自启动,可以参考http://os.51cto.com/art/201301/377515.htm

1. 首先查看服务器默认的运行级别是多少? 目的是在对应运行级别下建立服务的软连接。
 1> 执行命令#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. 将写好的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开头代表加载时自启动

以上已测试过,没有问题,同时有兴趣可以试试第二、三种方式。
posted @ 2013-06-04 11:18 David1228 阅读(412) | 评论 (0)编辑 收藏
VNCServer X 桌面默认为 twm, 这时连接进去只能看到终端界面,而看不到远程桌面界面。可修改 /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 &
修改完毕后须重新启动 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 的远程桌面一般),也可以通过 WEB 访问,在浏览器中输入http://192.168.0.252:5801 即可,VNC 默认的端口号为5801

转载:http://shaoruisky.blog.163.com/blog/static/92610707201151224518579/
posted @ 2013-03-24 13:07 David1228 阅读(2757) | 评论 (0)编辑 收藏
Spring2.5继续坚持了这个发展趋向,特别是为那些使用Java 5或更新版本java的开发人员提供了进一步简化而强大的新特性。这些新特性包括:注解驱动的依赖性注入(annotation-driven dependency injection),使用注解而非XML元数据来自动侦测classpath上的Spring组件,注解对生命周期方法的支持,一个新的web控制器模型将请求映射到加注解的方法上,在测试框架中支持Junit4,Spring XML命名空间的新增内容,等等。
项目中使用的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>
新增以下三项才可以使用注解功能
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"/> 注册一个单独的Spring post-processor.
一个没有实现任何接口的业务类,配置如下:
public class LogService extends Service{
public LogBiz(){}
@Resource //默认按名称查找bean. 如果找不到,则按类型匹配bean.
private BaseDao dao;
}
tomcat启动错误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默认按名称查找bean. 如果找不到,则按类型匹配bean.而名称dao没有找到,所以会根据BaseDAO匹配,但是BaseDAO是一个接口:
<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>
有两个实现了BaseDAO接口的类,所以spring就不知道应该使用哪一个了。直接抛出异常。
解决方法1:
我们可以看到baseDAO名称是唯一的, 所以如果想要按照名称匹配,则直接写baseDAO就可以了
@Resource
private BaseDAO baseDAO;
解决方法2:
@Autowired //默认按照类型匹配,同样应为有两个子类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 阅读(2485) | 评论 (0)编辑 收藏
     摘要: jdk并发部分,如果英文理解有点小难,可以参考http://www.yiibai.com/java6/java/util/concurrent/package-summary.html本篇转自:http://victorzhzh.iteye.com/blog/1011635很多时候我们希望任务可以定时的周期性的执行,在最初的JAVA工具类库中,通过Timer可以实现定时的周期性的需求,但是有一定的...  阅读全文
posted @ 2013-03-18 18:58 David1228 阅读(1752) | 评论 (0)编辑 收藏
使用开源云工具OpenNebula3.8.1在KVM环境下虚拟机迁移失败问题解决。
1、虚拟机迁移失败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、虚拟机迁移失败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
登陆到节点:
[root@bcec162 43]# virsh restore checkpoint 
错误:从 checkpoint 恢复域失败
错误: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节点的/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节点迁移到node153节点成功。
[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节点的/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节点迁移到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节点执行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,开启user=root和group=root. 
如果开启dynamic_ownership则恢复虚拟机也会报出上面的错误信息。
在node152节点上恢复虚拟机:
[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

转载请保持原链接:http://www.blogjava.net/ldwblog/archive/2013/03/08/396187.html
posted @ 2013-03-08 12:03 David1228 阅读(748) | 评论 (0)编辑 收藏
项目组内一位同事,在重构代码过程中将几个模块的Service层接口去掉后. 修改成了没有实现任何接口的类,并且继承了一个抽象基类。
然后我更新代码后执行系统中的该模块,发现部分表数据没有完整持久到数据库中。看了下代码和spring配置文件,原来调整后的Biz的业务类没有配置事务导致的。
修改了下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>

启动tomcat后报出如下错误信息:
[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
严重: 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

------------------------------------------
通过以上错误分析之:对于实现了接口的类,直接用了JDK的动态代理,把目标对象扔给JDK的Proxy,拿到代理对象就OK了。然而对于没有实现接口的类,Spring借助于CGLIB来实现代理。
解决办法:
当使用CGLIB来实现代理后,没有实现接口的类
1、 通过构造函数形式注入时必须有默认的构造函数,否则就会出现上面的异常。
2、通过生产setter或者getter方法注入。
3、通过修改Spring的CglibProxyFactory工厂类。

详细解析可以参照这篇文章:http://netfork.iteye.com/blog/286215
posted @ 2013-03-05 14:54 David1228 阅读(10740) | 评论 (0)编辑 收藏
仅列出标题
共16页: 上一页 1 2 3 4 5 6 7 8 9 下一页 Last 

<2024年11月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

常用链接

留言簿(4)

随笔分类

随笔档案

文章档案

新闻分类

新闻档案

相册

收藏夹

Java

Linux知识相关

Spring相关

云计算/Linux/虚拟化技术/

友情博客

多线程并发编程

开源技术

持久层技术相关

搜索

  •  

积分与排名

  • 积分 - 356922
  • 排名 - 154

最新评论

阅读排行榜

评论排行榜