Results 1 to 4 of 4

Thread: Problem with ProxyFactoryBean

  1. #1
    Join Date
    Nov 2007
    Posts
    7

    Default Problem with ProxyFactoryBean

    I am getting Null pointer exception

    at $Proxy0.getAll(Unknown Source)

    while trying to access Bean through ProxyFactoryBean. However if I directly use Impl class then I am getting all the values etc.

    Here are XML entries


    <bean id="deviceManager" class="org.springframework.aop.framework.ProxyFact oryBean">
    <property name="proxyInterfaces" value="com.xyz.jdbc.DeviceManager"/>
    <property name="interceptorNames">
    <list>
    <idref local="transactionInterceptor"/>
    <idref bean="deviceManagerSecurity"/>
    <idref local="deviceManagerTarget"/>
    </list>
    </property>
    </bean>
    <bean id="deviceManagerTarget" class="com.xyz.jdbc.DeviceManagerImpl">
    <property name="deviceDao">
    <bean class="com.xyz.jdbc.DeviceDaoSpring">
    <property name="dataSource" ref="dataSource"/>
    </bean>
    </property>
    <property name="mutableAclService" ref="aclService"/>
    </bean>

    <bean id="contactDataStore" class="com.xyz.domain.ContactDataStore">
    <property name="deviceManager" ref="deviceManager"/>
    </bean>


    Exception details

    [ERROR,ApplicationLifecycleAdvisor,AWT-EventQueue-0]
    java.lang.NullPointerException
    at com.cisco.csm.rbac.ui.ContactView.onApplicationEve nt(ContactView.java:219)
    at org.springframework.context.event.SimpleApplicatio nEventMulticaster$1.run(SimpleApplicationEventMult icaster.java:77)
    at org.springframework.core.task.SyncTaskExecutor.exe cute(SyncTaskExecutor.java:49)
    at org.springframework.context.event.SimpleApplicatio nEventMulticaster.multicastEvent(SimpleApplication EventMulticaster.java:75)
    at org.springframework.context.support.AbstractApplic ationContext.publishEvent(AbstractApplicationConte xt.java:246)
    at org.springframework.security.intercept.AbstractSec urityInterceptor.publishEvent(AbstractSecurityInte rceptor.java:492)
    at org.springframework.security.intercept.AbstractSec urityInterceptor.beforeInvocation(AbstractSecurity Interceptor.java:338)
    at org.springframework.security.intercept.method.aopa lliance.MethodSecurityInterceptor.invoke(MethodSec urityInterceptor.java:63)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :166)
    at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:107)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :166)
    at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:204)
    at $Proxy0.getAll(Unknown Source)


    I am developing acegi sample app using SpringRichClient and I am using acegi core tiger 1.0.5.

    I would appreciate any help.
    Last edited by sat; Dec 4th, 2007 at 05:00 AM.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    When posting code, please use [ code][/code ] tags. Next to that your configuration is wrong. You want to add a target, the bean you want to target is not an interceptor!

    Code:
    <property name="interceptorNames">
    <list>
    <idref local="transactionInterceptor"/>
    <idref bean="deviceManagerSecurity"/>
    <idref local="deviceManagerTarget"/>
    </list>
    </property>
    The line in red is your TARGET it isn't an interceptor which should be applied to your TARGET! Also it are interceptorNames not the actuall instances! As another improvement I would suggest registering the target as an anonymous inner bean, this prevents you from getting the wrong (non-proxied) one.

    Which would result in something like this.

    Code:
    <bean id="deviceManager" class="org.springframework.aop.framework.ProxyFactoryBean">
      <property name="proxyInterfaces" value="com.xyz.jdbc.DeviceManager"/>
      <propert name="target">
        <bean class="com.xyz.jdbc.DeviceManagerImpl">
          <property name="deviceDao">
            <bean class="com.xyz.jdbc.DeviceDaoSpring">
              <property name="dataSource" ref="dataSource"/>
            </bean>
          </property>
          <property name="mutableAclService" ref="aclService"/>
        </bean>
      </property>
      <property name="interceptorNames">
        <list>
        <value>transactionInterceptor</value>
        <value>deviceManagerSecurity</value>
      </list>
      </property>
    </bean>
    
    <bean id="contactDataStore" class="com.xyz.domain.ContactDataStore">
      <property name="deviceManager" ref="deviceManager"/>
    </bean>
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Nov 2007
    Posts
    7

    Default Problem with ProxyFactoryBean

    I am still getting the same exception even with changed configuration

    Code:
       <bean id="deviceManager" class="org.springframework.aop.framework.ProxyFactoryBean">
         <property name="proxyInterfaces" value="com.xyz.jdbc.DeviceManager"/>
         	<property name="target">
         	   <bean class="com.xyz.jdbc.DeviceManagerImpl">
         	      	<property name="deviceDao">
           				<bean class="com.xyz.jdbc.DeviceDaoSpring">
    	       				<property name="dataSource" ref="dataSource"/>
           				</bean>
           			</property>
           			<property name="mutableAclService" ref="aclService"/>
           		</bean>
           	</property>
       	   <property name="interceptorNames">
           <list>
             <idref local="transactionInterceptor"/>
             <idref bean="deviceManagerSecurity"/>
           </list>
         </property>
       </bean>
    
        <bean id="contactDataStore" class="com.xyz.domain.ContactDataStore">
        	<property name="deviceManager" ref="deviceManager"/>
        </bean>
    Exception
    at org.springframework.context.event.SimpleApplicatio nEventMulticaster$1.run(SimpleApplicationEventMult icaster.java:77)
    at org.springframework.core.task.SyncTaskExecutor.exe cute(SyncTaskExecutor.java:49)
    at org.springframework.context.event.SimpleApplicatio nEventMulticaster.multicastEvent(SimpleApplication EventMulticaster.java:75)
    at org.springframework.context.support.AbstractApplic ationContext.publishEvent(AbstractApplicationConte xt.java:246)
    at org.springframework.security.intercept.AbstractSec urityInterceptor.publishEvent(AbstractSecurityInte rceptor.java:492)
    at org.springframework.security.intercept.AbstractSec urityInterceptor.beforeInvocation(AbstractSecurity Interceptor.java:328)
    at org.springframework.security.intercept.method.aopa lliance.MethodSecurityInterceptor.invoke(MethodSec urityInterceptor.java:63)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :166)
    at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:107)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :166)
    at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:204)
    at $Proxy0.getAll(Unknown Source)


    This is very much the same from acegi contact sample but somehow I am not able to figure what is missing from my code/xml file

    Here is the configuration from sample contact application
    Code:
       <bean id="contactManager" class="org.springframework.aop.framework.ProxyFactoryBean">
         <property name="proxyInterfaces" value="sample.contact.ContactManager"/>
         <property name="interceptorNames">
           <list>
             <idref local="transactionInterceptor"/>
             <idref bean="contactManagerSecurity"/>
             <idref local="contactManagerTarget"/>
           </list>
         </property>
       </bean>
    
       <bean id="contactManagerTarget" class="sample.contact.ContactManagerBackend">
    	   <property name="contactDao">
           <bean class="sample.contact.ContactDaoSpring">
    	       <property name="dataSource"><ref local="dataSource"/></property>
           </bean>
         </property>
         <property name="mutableAclService" ref="aclService"/>
       </bean>
    Last edited by sat; Dec 4th, 2007 at 07:36 AM. Reason: added sample XML

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    As I stated before the interceptorNames are the NAMES of the interceptors NOT the interceptors themselves!!!!!
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •