Featured post
spring - Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0' defined in ServletContext resource -
problem :
i creating pointcut execution of method in class . class controller class , denoted annotation @controller , hence no bean needed same required aspect. attaching dispathcher servlet code , aspect , controller class.can identify problem is.
dispatcher servlet :
<?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" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <context:annotation-config /> <context:spring-configured /> <aop:aspectj-autoproxy /> <bean id="loggerbean" class="com.persistent.eap.aop.loggeraspect" /> <bean class="org.springframework.web.servlet.mvc.annotation.defaultannotationhandlermapping" > <property name="order" value="0" /> </bean> <bean class="org.springframework.web.servlet.mvc.annotation.annotationmethodhandleradapter" /> <bean class="com.persistent.eap.validators.userregistrationvalidator" /> <bean id="userregistrationservice" class="com.persistent.eap.service.impl.userregistrationserviceimpl" /> <bean id="useroperationsservice" class="com.persistent.eap.service.impl.useroperationsserviceimpl" /> <bean id="messagesource" class="org.springframework.context.support.resourcebundlemessagesource"> <property name="basename" value="messages"/> </bean> <bean id="tilesviewresolver" class="org.springframework.web.servlet.view.urlbasedviewresolver"> <property name="viewclass" value="org.springframework.web.servlet.view.tiles2.tilesview"/> </bean> <bean id="tilesconfigurer" class="org.springframework.web.servlet.view.tiles2.tilesconfigurer" p:definitions="/web-inf/tiles-defs.xml" /> <context:component-scan base-package="com.persistent.eap.controllers" /> <context:component-scan base-package="com.persistent.eap.service" /> <context:component-scan base-package="com.persistent.eap.dao" /> <import resource="databasecontext.xml"/> <bean class="org.springframework.web.servlet.handler.simpleurlhandlermapping" > <property name="order" value="1" /> <property name="mappings"> <value> /*.htm=urlcontroller </value> </property> </bean> <bean id="urlcontroller" class="org.springframework.web.servlet.mvc.urlfilenameviewcontroller" /> </beans>
aspect :
package com.persistent.eap.aop; import org.aspectj.lang.proceedingjoinpoint; import org.aspectj.lang.annotation.aspect; import org.aspectj.lang.annotation.around; import org.aspectj.lang.annotation.pointcut; //import org.aspectj.lang.annotation.before; @aspect public class loggeraspect { @pointcut("execution(* com.persistent.eap.controllers.userregistrationcontroller.setupform(..))") public void controllermethods(){} @around("controllermethods()") public object controllermethodcall(proceedingjoinpoint call) throws throwable{ system.out.println("[logging info : entering method "+call.toshortstring()+" ]"); object point=call.proceed(); system.out.println("[logging info : exiting method "+call.toshortstring()+" return "+point+" ]"); return point; } }
controller class :
package com.persistent.eap.controllers; import org.springframework.beans.factory.annotation.autowired; import org.springframework.stereotype.controller; import org.springframework.ui.modelmap; import org.springframework.validation.bindingresult; import org.springframework.web.bind.annotation.modelattribute; import org.springframework.web.bind.annotation.requestmapping; import org.springframework.web.bind.annotation.requestmethod; import com.persistent.eap.domain.userdetails; import com.persistent.eap.service.intfc.userregistrationservice; import com.persistent.eap.validators.userregistrationvalidator; @controller @requestmapping("/userregistrationform.htm") public class userregistrationcontroller { private userregistrationservice userregistrationservice; private userregistrationvalidator userregistrationvalidator; @autowired public userregistrationcontroller(userregistrationservice userregistrationservice ,userregistrationvalidator userregistrationvalidator) { this.userregistrationservice = userregistrationservice; this.userregistrationvalidator = userregistrationvalidator; } @requestmapping(method=requestmethod.get) public string setupform(modelmap model){ userdetails userdetails = new userdetails(); model.addattribute("userdetails", userdetails); return "userregistrationform"; } @requestmapping(method=requestmethod.post) public string onsubmit(@modelattribute("userdetails") userdetails userdetails,bindingresult result){ userregistrationvalidator.validate(userdetails, result); if(result.haserrors()){ return "userregistrationform"; } else{ system.out.println(userdetails.getid()+" "+userdetails.getusername()); userregistrationservice.registeruserdetails(userdetails); return "userregistrationsuccess"; } } }
error on console :
severe: standardwrapper.throwable org.springframework.beans.factory.beancreationexception: error creating bean name 'org.springframework.web.servlet.mvc.annotation.defaultannotationhandlermapping#0' defined in servletcontext resource [/web-inf/dispatcher-servlet.xml]: initialization of bean failed; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'userregistrationcontroller' defined in file [c:\documents , settings\samiksha_kalra\desktop\vmforce\eclipseworkspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\eapproject\web-inf\classes\com\persistent\eap\controllers\userregistrationcontroller.class]: initialization of bean failed; nested exception org.springframework.aop.framework.aopconfigexception: not generate cglib subclass of class [class com.persistent.eap.controllers.userregistrationcontroller]: common causes of problem include using final class or non-visible class; nested exception java.lang.illegalargumentexception: superclass has no null constructors no arguments given @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:527) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:456) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:291) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:222) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:288) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:190) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:580) @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:895) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:425) @ org.springframework.web.servlet.frameworkservlet.createwebapplicationcontext(frameworkservlet.java:442) @ org.springframework.web.servlet.frameworkservlet.createwebapplicationcontext(frameworkservlet.java:458) @ org.springframework.web.servlet.frameworkservlet.initwebapplicationcontext(frameworkservlet.java:339) @ org.springframework.web.servlet.frameworkservlet.initservletbean(frameworkservlet.java:306) @ org.springframework.web.servlet.httpservletbean.init(httpservletbean.java:127) @ javax.servlet.genericservlet.init(genericservlet.java:212) @ org.apache.catalina.core.standardwrapper.loadservlet(standardwrapper.java:1173) @ org.apache.catalina.core.standardwrapper.load(standardwrapper.java:993) @ org.apache.catalina.core.standardcontext.loadonstartup(standardcontext.java:4350) @ org.apache.catalina.core.standardcontext.start(standardcontext.java:4659) @ org.apache.catalina.core.containerbase.start(containerbase.java:1045) @ org.apache.catalina.core.standardhost.start(standardhost.java:785) @ org.apache.catalina.core.containerbase.start(containerbase.java:1045) @ org.apache.catalina.core.standardengine.start(standardengine.java:445) @ org.apache.catalina.core.standardservice.start(standardservice.java:519) @ org.apache.catalina.core.standardserver.start(standardserver.java:710) @ org.apache.catalina.startup.catalina.start(catalina.java:581) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ org.apache.catalina.startup.bootstrap.start(bootstrap.java:289) @ org.apache.catalina.startup.bootstrap.main(bootstrap.java:414) caused by: org.springframework.beans.factory.beancreationexception: error creating bean name 'userregistrationcontroller' defined in file [c:\documents , settings\samiksha_kalra\desktop\vmforce\eclipseworkspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\eapproject\web-inf\classes\com\persistent\eap\controllers\userregistrationcontroller.class]: initialization of bean failed; nested exception org.springframework.aop.framework.aopconfigexception: not generate cglib subclass of class [class com.persistent.eap.controllers.userregistrationcontroller]: common causes of problem include using final class or non-visible class; nested exception java.lang.illegalargumentexception: superclass has no null constructors no arguments given @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:527) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:456) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:291) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:222) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:288) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:190) @ org.springframework.context.support.abstractapplicationcontext.getbean(abstractapplicationcontext.java:1075) @ org.springframework.web.servlet.handler.abstracturlhandlermapping.registerhandler(abstracturlhandlermapping.java:383) @ org.springframework.web.servlet.handler.abstracturlhandlermapping.registerhandler(abstracturlhandlermapping.java:362) @ org.springframework.web.servlet.handler.abstractdetectingurlhandlermapping.detecthandlers(abstractdetectingurlhandlermapping.java:82) @ org.springframework.web.servlet.handler.abstractdetectingurlhandlermapping.initapplicationcontext(abstractdetectingurlhandlermapping.java:58) @ org.springframework.context.support.applicationobjectsupport.initapplicationcontext(applicationobjectsupport.java:119) @ org.springframework.web.context.support.webapplicationobjectsupport.initapplicationcontext(webapplicationobjectsupport.java:72) @ org.springframework.context.support.applicationobjectsupport.setapplicationcontext(applicationobjectsupport.java:73) @ org.springframework.context.support.applicationcontextawareprocessor.invokeawareinterfaces(applicationcontextawareprocessor.java:106) @ org.springframework.context.support.applicationcontextawareprocessor.postprocessbeforeinitialization(applicationcontextawareprocessor.java:85) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.applybeanpostprocessorsbeforeinitialization(abstractautowirecapablebeanfactory.java:394) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1413) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:519) ... 31 more caused by: org.springframework.aop.framework.aopconfigexception: not generate cglib subclass of class [class com.persistent.eap.controllers.userregistrationcontroller]: common causes of problem include using final class or non-visible class; nested exception java.lang.illegalargumentexception: superclass has no null constructors no arguments given @ org.springframework.aop.framework.cglib2aopproxy.getproxy(cglib2aopproxy.java:212) @ org.springframework.aop.framework.proxyfactory.getproxy(proxyfactory.java:112) @ org.springframework.aop.framework.autoproxy.abstractautoproxycreator.createproxy(abstractautoproxycreator.java:476) @ org.springframework.aop.framework.autoproxy.abstractautoproxycreator.wrapifnecessary(abstractautoproxycreator.java:362) @ org.springframework.aop.framework.autoproxy.abstractautoproxycreator.postprocessafterinitialization(abstractautoproxycreator.java:322) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.applybeanpostprocessorsafterinitialization(abstractautowirecapablebeanfactory.java:407) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1426) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:519) ... 49 more caused by: java.lang.illegalargumentexception: superclass has no null constructors no arguments given @ net.sf.cglib.proxy.enhancer.emitconstructors(enhancer.java:718) @ net.sf.cglib.proxy.enhancer.generateclass(enhancer.java:499) @ net.sf.cglib.transform.transformingclassgenerator.generateclass(transformingclassgenerator.java:33) @ net.sf.cglib.core.defaultgeneratorstrategy.generate(defaultgeneratorstrategy.java:25) @ net.sf.cglib.core.abstractclassgenerator.create(abstractclassgenerator.java:216) @ net.sf.cglib.proxy.enhancer.createhelper(enhancer.java:377) @ net.sf.cglib.proxy.enhancer.create(enhancer.java:285) @ org.springframework.aop.framework.cglib2aopproxy.getproxy(cglib2aopproxy.java:200) ... 56 more dec 20, 2010 6:28:42 pm org.apache.catalina.core.standardcontext loadonstartup severe: servlet /eapproject threw load() exception java.lang.illegalargumentexception: superclass has no null constructors no arguments given @ net.sf.cglib.proxy.enhancer.emitconstructors(enhancer.java:718) @ net.sf.cglib.proxy.enhancer.generateclass(enhancer.java:499) @ net.sf.cglib.transform.transformingclassgenerator.generateclass(transformingclassgenerator.java:33) @ net.sf.cglib.core.defaultgeneratorstrategy.generate(defaultgeneratorstrategy.java:25) @ net.sf.cglib.core.abstractclassgenerator.create(abstractclassgenerator.java:216) @ net.sf.cglib.proxy.enhancer.createhelper(enhancer.java:377) @ net.sf.cglib.proxy.enhancer.create(enhancer.java:285) @ org.springframework.aop.framework.cglib2aopproxy.getproxy(cglib2aopproxy.java:200) @ org.springframework.aop.framework.proxyfactory.getproxy(proxyfactory.java:112) @ org.springframework.aop.framework.autoproxy.abstractautoproxycreator.createproxy(abstractautoproxycreator.java:476) @ org.springframework.aop.framework.autoproxy.abstractautoproxycreator.wrapifnecessary(abstractautoproxycreator.java:362) @ org.springframework.aop.framework.autoproxy.abstractautoproxycreator.postprocessafterinitialization(abstractautoproxycreator.java:322) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.applybeanpostprocessorsafterinitialization(abstractautowirecapablebeanfactory.java:407) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1426) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:519) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:456) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:291) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:222) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:288) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:190) @ org.springframework.context.support.abstractapplicationcontext.getbean(abstractapplicationcontext.java:1075) @ org.springframework.web.servlet.handler.abstracturlhandlermapping.registerhandler(abstracturlhandlermapping.java:383) @ org.springframework.web.servlet.handler.abstracturlhandlermapping.registerhandler(abstracturlhandlermapping.java:362) @ org.springframework.web.servlet.handler.abstractdetectingurlhandlermapping.detecthandlers(abstractdetectingurlhandlermapping.java:82) @ org.springframework.web.servlet.handler.abstractdetectingurlhandlermapping.initapplicationcontext(abstractdetectingurlhandlermapping.java:58) @ org.springframework.context.support.applicationobjectsupport.initapplicationcontext(applicationobjectsupport.java:119) @ org.springframework.web.context.support.webapplicationobjectsupport.initapplicationcontext(webapplicationobjectsupport.java:72) @ org.springframework.context.support.applicationobjectsupport.setapplicationcontext(applicationobjectsupport.java:73) @ org.springframework.context.support.applicationcontextawareprocessor.invokeawareinterfaces(applicationcontextawareprocessor.java:106) @ org.springframework.context.support.applicationcontextawareprocessor.postprocessbeforeinitialization(applicationcontextawareprocessor.java:85) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.applybeanpostprocessorsbeforeinitialization(abstractautowirecapablebeanfactory.java:394) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1413) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:519) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:456) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:291) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:222) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:288) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:190) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:580) @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:895) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:425) @ org.springframework.web.servlet.frameworkservlet.createwebapplicationcontext(frameworkservlet.java:442) @ org.springframework.web.servlet.frameworkservlet.createwebapplicationcontext(frameworkservlet.java:458) @ org.springframework.web.servlet.frameworkservlet.initwebapplicationcontext(frameworkservlet.java:339) @ org.springframework.web.servlet.frameworkservlet.initservletbean(frameworkservlet.java:306) @ org.springframework.web.servlet.httpservletbean.init(httpservletbean.java:127) @ javax.servlet.genericservlet.init(genericservlet.java:212) @ org.apache.catalina.core.standardwrapper.loadservlet(standardwrapper.java:1173) @ org.apache.catalina.core.standardwrapper.load(standardwrapper.java:993) @ org.apache.catalina.core.standardcontext.loadonstartup(standardcontext.java:4350) @ org.apache.catalina.core.standardcontext.start(standardcontext.java:4659) @ org.apache.catalina.core.containerbase.start(containerbase.java:1045) @ org.apache.catalina.core.standardhost.start(standardhost.java:785) @ org.apache.catalina.core.containerbase.start(containerbase.java:1045) @ org.apache.catalina.core.standardengine.start(standardengine.java:445) @ org.apache.catalina.core.standardservice.start(standardservice.java:519) @ org.apache.catalina.core.standardserver.start(standardserver.java:710) @ org.apache.catalina.startup.catalina.start(catalina.java:581) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ org.apache.catalina.startup.bootstrap.start(bootstrap.java:289) @ org.apache.catalina.startup.bootstrap.main(bootstrap.java:414)
this limitation in spring aop. when use aspectj pointcuts weave aspects beans, spring use cglib generate subclass of target, , invoke aspects subclass.
if target class not have public default constructor, however, fail. cglib have ability handle this, hidden behind spring aop stuff , can't change behaviour.
i can suggest go using setter injection controller, rather constructor injection. it's not ideal, know, can't think of other workaround.
- Get link
- X
- Other Apps
Comments
Post a Comment