web-dev-qa-db-ja.com

ServletContextリソースで定義された「org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0」という名前のBeanの作成エラー

問題:

クラスでメソッドを実行するためのポイントカットを作成しています。このクラスはコントローラークラスであり、アノテーション@Controllerによって示されるため、アスペクトで必要とされるものにBeanは必要ありません。 dispathcherサーブレットコード、アスペクト、およびコントローラークラスを添付しています。誰かが問題を特定できますか。

ディスパッチャーサーベット:

<?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>

側面 :

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()+" with return as "+point+" ]");
     return point;
     }



}

コントローラークラス:

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";
  }
 }

}

コンソールのエラー:

SEVERE: StandardWrapper.Throwable
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRegistrationController' defined in file [C:\Documents and 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 is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.persistent.eap.controllers.UserRegistrationController]: 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:527)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:456)
 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.Java:291)
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.Java:222)
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:288)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:190)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.Java:580)
 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.Java:895)
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.Java:425)
 at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.Java:442)
 at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.Java:458)
 at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.Java:339)
 at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.Java:306)
 at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.Java:127)
 at javax.servlet.GenericServlet.init(GenericServlet.Java:212)
 at org.Apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.Java:1173)
 at org.Apache.catalina.core.StandardWrapper.load(StandardWrapper.Java:993)
 at org.Apache.catalina.core.StandardContext.loadOnStartup(StandardContext.Java:4350)
 at org.Apache.catalina.core.StandardContext.start(StandardContext.Java:4659)
 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(Unknown Source)
 at Sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 at Java.lang.reflect.Method.invoke(Unknown Source)
 at org.Apache.catalina.startup.Bootstrap.start(Bootstrap.Java:289)
 at org.Apache.catalina.startup.Bootstrap.main(Bootstrap.Java:414)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRegistrationController' defined in file [C:\Documents and 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 is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.persistent.eap.controllers.UserRegistrationController]: 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:527)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:456)
 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.Java:291)
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.Java:222)
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:288)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:190)
 at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.Java:1075)
 at org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.registerHandler(AbstractUrlHandlerMapping.Java:383)
 at org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.registerHandler(AbstractUrlHandlerMapping.Java:362)
 at org.springframework.web.servlet.handler.AbstractDetectingUrlHandlerMapping.detectHandlers(AbstractDetectingUrlHandlerMapping.Java:82)
 at org.springframework.web.servlet.handler.AbstractDetectingUrlHandlerMapping.initApplicationContext(AbstractDetectingUrlHandlerMapping.Java:58)
 at org.springframework.context.support.ApplicationObjectSupport.initApplicationContext(ApplicationObjectSupport.Java:119)
 at org.springframework.web.context.support.WebApplicationObjectSupport.initApplicationContext(WebApplicationObjectSupport.Java:72)
 at org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.Java:73)
 at org.springframework.context.support.ApplicationContextAwareProcessor.invokeAwareInterfaces(ApplicationContextAwareProcessor.Java:106)
 at org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.Java:85)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.Java:394)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.Java:1413)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:519)
 ... 31 more
Caused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.persistent.eap.controllers.UserRegistrationController]: 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:212)
 at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.Java:112)
 at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.Java:476)
 at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.Java:362)
 at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.Java:322)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.Java:407)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.Java:1426)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:519)
 ... 49 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: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 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:200)
 at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.Java:112)
 at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.Java:476)
 at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.Java:362)
 at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.Java:322)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.Java:407)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.Java:1426)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:519)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:456)
 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.Java:291)
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.Java:222)
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:288)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:190)
 at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.Java:1075)
 at org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.registerHandler(AbstractUrlHandlerMapping.Java:383)
 at org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.registerHandler(AbstractUrlHandlerMapping.Java:362)
 at org.springframework.web.servlet.handler.AbstractDetectingUrlHandlerMapping.detectHandlers(AbstractDetectingUrlHandlerMapping.Java:82)
 at org.springframework.web.servlet.handler.AbstractDetectingUrlHandlerMapping.initApplicationContext(AbstractDetectingUrlHandlerMapping.Java:58)
 at org.springframework.context.support.ApplicationObjectSupport.initApplicationContext(ApplicationObjectSupport.Java:119)
 at org.springframework.web.context.support.WebApplicationObjectSupport.initApplicationContext(WebApplicationObjectSupport.Java:72)
 at org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.Java:73)
 at org.springframework.context.support.ApplicationContextAwareProcessor.invokeAwareInterfaces(ApplicationContextAwareProcessor.Java:106)
 at org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.Java:85)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.Java:394)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.Java:1413)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:519)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:456)
 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.Java:291)
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.Java:222)
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:288)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:190)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.Java:580)
 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.Java:895)
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.Java:425)
 at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.Java:442)
 at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.Java:458)
 at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.Java:339)
 at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.Java:306)
 at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.Java:127)
 at javax.servlet.GenericServlet.init(GenericServlet.Java:212)
 at org.Apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.Java:1173)
 at org.Apache.catalina.core.StandardWrapper.load(StandardWrapper.Java:993)
 at org.Apache.catalina.core.StandardContext.loadOnStartup(StandardContext.Java:4350)
 at org.Apache.catalina.core.StandardContext.start(StandardContext.Java:4659)
 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(Unknown Source)
 at Sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 at Java.lang.reflect.Method.invoke(Unknown Source)
 at org.Apache.catalina.startup.Bootstrap.start(Bootstrap.Java:289)
 at org.Apache.catalina.startup.Bootstrap.main(Bootstrap.Java:414)
17
user548656

これは、Spring AOPの制限です。 AspectJポイントカットを使用してアスペクトをBeanに織り込むと、SpringはCGLIBを使用してターゲットのサブクラスを生成し、そのサブクラスからアスペクトを呼び出します。

ただし、ターゲットクラスにパブリックデフォルトコンストラクターがない場合、これは失敗します。 CGLIBにはこれを処理する機能がありますが、これはすべてSpring AOPの背後に隠されており、その動作を変更することはできません。

コンストラクターインジェクションではなく、コントローラーにセッターインジェクションを使用することに戻ることをお勧めします。理想的ではありませんが、他の回避策は考えられません。

37
skaffman