Announcement Announcement Module
Collapse
No announcement yet.
TypeMisMatch Exception for AOP-proxied class Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • TypeMisMatch Exception for AOP-proxied class

    I've had no problem implementing AOP on any of the new service classes I'm doing active development on, which have been referenced by controllers. However, I'm trying to implement AOP on a service-layer class that has been in the codebase for some time, and a controller in the action-servlet causes a TypeMisMatch exception when trying to reference it

    Action-servlet
    Code:
    <bean id="familyTravelersController" class="com.website.package.controller.FamilyTravelersController">
    			<property name="reviewService" ref="reviewService"/>
    		</bean>
    Service declaration
    Code:
    <bean id="reviewService" class="com.website.package.service.impl.ReviewService"/>
    AOP declaration
    Code:
    <bean name="pointcut.eventAdvice.friendAddsReviewOrFVM" class="org.springframework.aop.support.NameMatchMethodPointcutAdvisor">
     		<property name="advice" ref="eventAdvice"/>
    		<property name="mappedName" value="saveReviewDTO"/>
    	</bean>
        <bean id="IReviewService" class="org.springframework.aop.framework.ProxyFactoryBean">
            <property name = "proxyInterfaces">
                <value>com.website.package.service.IReviewService</value>
            </property>
            <property name = "interceptorNames">
                <list><value>pointcut.eventAdvice.friendAddsReviewOrFVM</value></list> 
            </property>
            <property name = "target">    
                <ref bean = "reviewService"/>
            </property>    
        </bean>
    Stack Trace:
    Code:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'familyTravelersController' defined in ServletContext resource [/WEB-INF/travel/action-servlet.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
    PropertyAccessException 1: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy40] to required type [com.website.package.service.impl.ReviewService] for property 'reviewService'; nested exception is java.lang.IllegalArgumentException: No matching editors or conversion strategy found
    	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:975)
    	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:729)
    	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:416)
    	org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
    	org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141)
    	org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
    	org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:156)
    	org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:642)
    	org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.registerHandler(AbstractUrlHandlerMapping.java:223)
    	org.springframework.web.servlet.handler.SimpleUrlHandlerMapping.registerHandlers(SimpleUrlHandlerMapping.java:114)
    	org.springframework.web.servlet.handler.SimpleUrlHandlerMapping.initApplicationContext(SimpleUrlHandlerMapping.java:92)
    	org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.java:73)
    	org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:86)
    	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:297)
    	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1025)
    	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:420)
    	org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
    	org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141)
    	org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
    	org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:156)
    	org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:290)
    	org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:348)
    	org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:156)
    	org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:308)
    	org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:252)
    	org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:221)
    	org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:115)
    	javax.servlet.GenericServlet.init(GenericServlet.java:211)
    	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    	...etc...
    I've compared this to all the other AOP proxies I've created, but I cant see why this one is failing. Any ideas?

  • #2
    Your 'FamilyTravelersController' is not programmed to interfaces it uses a reference to the 'com.website.package.service.impl.ReviewService' whereas it should use the 'com.website.package.service.IReviewService'.

    The proxy is an instance of your interface not of your concrete class.

    That is also clearly stated by your exception.

    Just as a side note, I would declare your target as an anonymous inner bean, that way you cannot reference the unproxied instance.

    Code:
    <bean name="pointcut.eventAdvice.friendAddsReviewOrFVM" class="org.springframework.aop.support.NameMatchMethodPointcutAdvisor">
    	<property name="advice" ref="eventAdvice"/>
    	<property name="mappedName" value="saveReviewDTO"/>
    </bean>
    
    <bean id="IReviewService" class="org.springframework.aop.framework.ProxyFactoryBean">
    	<property name = "proxyInterfaces" value="com.website.package.service.IReviewService"/>
    	<property name = "interceptorNames">
    		<list><value>pointcut.eventAdvice.friendAddsReviewOrFVM</value></list> 
    	</property>
    	<property name = "target">    
    		<bean class="com.website.package.service.impl.ReviewService"/>
    	</property>    
    </bean>
    
    <bean id="familyTravelersController" class="com.website.package.controller.FamilyTravelersController">
    	<property name="reviewService" ref="IReviewService"/>
    </bean>

    Comment


    • #3
      Now working

      Thanks for the help. I had implemented your fix to no avail, but then decided to take a look at what my controller was expecting to receive, and it seems I had foolishly set it to take in the Implemented class, not the interface. Works great now, Thanks Again!

      Comment

      Working...
      X