PDA

View Full Version : Not able to create RmiProxyFactoryBean



c2tarun
Feb 22nd, 2012, 01:23 AM
Hi friends,

I am trying to implement the example on page: http://codetojoy.blogspot.in/2007/12/zero-to-rmi-in-minutes-or-i-heart.html

in RAD(eclipse). I am able to Run the server program properly but when I trying to run the client program I am getting BeanCreationException when trying to inject RmiProxyFactoryBean object.

Can anyone please help?

Marten Deinum
Feb 22nd, 2012, 02:46 AM
Post code and stacktrace. When doing so use [ code][/code ] tags.

c2tarun
Feb 22nd, 2012, 08:15 PM
Post code and stacktrace. When doing so use [ code][/code ] tags.


Here are the service side classes:



package com.service;

public class MathServiceImpl implements MathService {

@Override
public int add(int a, int b) {
// TODO Auto-generated method stub
return a+b;
}

@Override
public int pro(int a, int b) {
// TODO Auto-generated method stub
return a*b;
}

}





package com.service;

import org.springframework.context.ApplicationContext;

public class MathServiceStart {

public static void main(String[] args) {
try {

ApplicationContext ctx = new ClassPathXmlApplicationContext(
"MathService.xml");

} catch (Exception e) {
System.out.println("Inside catch");
e.printStackTrace();
}

}

}


Service XML (MathService.xml)




<bean id="mathService" class="com.service.MathServiceImpl" />
<bean
class="org.springframework.remoting.rmi.RmiServiceExporte r">

<property name="serviceName" value="MathService"/>
<property name="service" ref="mathService"/>
<property name="serviceInterface" value="com.service.MathService"/>
<property name="registryPort" value="9911"/>
</bean>


CLIENT side codes



package com.math.caller;


public class MathCaller {

private MathService ms;

public MathService getMs() {
return ms;
}

public void setMs(MathService ms) {
this.ms = ms;
}

public void add() {
System.out.println(ms.add(10, 20));
}

public void pro() {
System.out.println(ms.pro(5, 25));
}

}





package com.math.caller;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlAp plicationContext;

public class MathCallerClient {

public static void main(String[] args) {
ApplicationContext bf = new ClassPathXmlApplicationContext("client.xml");
MathCaller mc = (MathCaller) bf.getBean("mathCaller");

mc.add();
mc.pro();
}

}



Client side XML




<bean id="MathService"
class="org.springframework.remoting.rmi.RmiProxyFactoryBe an">

<property name="serviceUrl" value="rmi://localhost:9911/MathService"/>
<property name="serviceInerface" value="com.math.caller.MathService"></property>
</bean>

<bean id="mathCaller" class="com.math.caller.MathCaller">
<property name="ms" ref="MathService" />
</bean>


When I am executing MathServiceStart class I am getting no error or exception. But when I am executing to access the RMI service I am getting the following exception.




23 Feb, 2012 7:39:25 AM org.springframework.context.support.AbstractApplic ationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlAp plicationContext@61b383e9: display name [org.springframework.context.support.ClassPathXmlAp plicationContext@61b383e9]; startup date [Thu Feb 23 07:39:25 IST 2012]; root of context hierarchy
23 Feb, 2012 7:39:25 AM org.springframework.beans.factory.xml.XmlBeanDefin itionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [client.xml]
23 Feb, 2012 7:39:25 AM org.springframework.context.support.AbstractApplic ationContext obtainFreshBeanFactory
INFO: Bean factory for application context [org.springframework.context.support.ClassPathXmlAp plicationContext@61b383e9]: org.springframework.beans.factory.support.DefaultL istableBeanFactory@651dba45
23 Feb, 2012 7:39:25 AM org.springframework.beans.factory.support.DefaultL istableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultL istableBeanFactory@651dba45: defining beans [MathService,mathCaller]; root of factory hierarchy
23 Feb, 2012 7:39:25 AM org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry destroySingletons
INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultL istableBeanFactory@651dba45: defining beans [MathService,mathCaller]; root of factory hierarchy
Exception in thread "main" org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'MathService' defined in class path resource [client.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'serviceInerface' of bean class [org.springframework.remoting.rmi.RmiProxyFactoryBe an]: Bean property 'serviceInerface' is not writable or has an invalid setter method. Did you mean 'serviceInterface'?
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1279)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:1010)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:472)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 64)
at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)
at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:261 )
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:423)
at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:728)
at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:380)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.math.caller.MathCallerClient.main(MathCallerCl ient.java:9)
Caused by: org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'serviceInerface' of bean class [org.springframework.remoting.rmi.RmiProxyFactoryBe an]: Bean property 'serviceInerface' is not writable or has an invalid setter method. Did you mean 'serviceInterface'?
at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:801)
at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:651)
at org.springframework.beans.AbstractPropertyAccessor .setPropertyValues(AbstractPropertyAccessor.java:7 8)
at org.springframework.beans.AbstractPropertyAccessor .setPropertyValues(AbstractPropertyAccessor.java:5 9)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1276)
... 16 more


Following are my file structures for Client 4724 and
Service 4725

Marten Deinum
Feb 23rd, 2012, 12:55 AM
Have you read the stacktrace?



Invalid property 'serviceInerface' of bean class [org.springframework.remoting.rmi.RmiProxyFactoryBe an]: Bean property 'serviceInerface' is not writable or has an invalid setter method. Did you mean 'serviceInterface'?


Context


<bean id="MathService"
class="org.springframework.remoting.rmi.RmiProxyFactoryBe an">

<property name="serviceUrl" value="rmi://localhost:9911/MathService"/>
<property name="serviceInerface" value="com.math.caller.MathService"></property>
</bean>

c2tarun
Feb 23rd, 2012, 12:56 AM
OMG!!! sorry I'll try it today. Thanks a lot.