• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

org.springframework.beans.NotWritablePropertyException: Invalid property while sending email

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,

I am a new to spring framework.

I want to send an email to user for alert purpose.

I have want to expose this as a cxf web service.

After creating classes from WSDL2Java plug in i have implemented necessary methods in my NotificationServiceImpl class.

Following is my XML configuration.

XML:
===

<bean class="com.pmc.ws.notificationservice.NotificationServiceImpl">
<property name="mailSender" ref="mailSender"/>
<property name="messageTemplate" ref="messageTemplate"/>
</bean>


<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="10.60.10.210"/>
<!-- Uncomment if you need to authenticate with your SMTP Server -->
<property name="username" value="Live.Server@abc.in"/>
<property name="password" value="abc123"/>
<property name="port" value="25"/>
<property name="javaMailProperties">
<value>
mail.smtp.auth=true
</value>
</property>
</bean>

<bean id="messageTemplate" class="org.springframework.mail.SimpleMailMessage" scope="prototype">
<property name="from" value="Live.Server@abc.in"/>
</bean>


Following is my NotificationServiceImpl class
=============================

/**
* Please modify this class to meet your needs
* This class is not complete
*/

package com.pmc.ws.notificationservice;

import java.util.logging.Logger;

import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;

/**
* This class was generated by Progress FUSE Services Framework 2.2.x-fuse-SNAPSHOT
* Tue Jul 20 10:22:34 IST 2010
* Generated source version: 2.2.x-fuse-SNAPSHOT
*
*/

@javax.jws.WebService(
serviceName = "NotificationService",
portName = "NotificationServiceSOAP",
targetNamespace = "http://www.ws.pmc.com/NotificationService/",
endpointInterface = "com.pmc.ws.notificationservice.NotificationService")

public class NotificationServiceImpl implements NotificationService {

private static final Logger LOG = Logger.getLogger(NotificationServiceImpl.class.getName());
private MailSender mailSender = null;
private SimpleMailMessage messageTemplate = null;

public MailSender getMailSender() {
return mailSender;
}
public void setMailSender(MailSender mailSender) {
this.mailSender = mailSender;
}
public SimpleMailMessage getMessageTemplate() {
return messageTemplate;
}
public void setMessageTemplate(SimpleMailMessage messageTemplate) {
this.messageTemplate = messageTemplate;
}
public void prepareAndSendEmail (){
messageTemplate.setTo("chirag.borkar@abc.in");
messageTemplate.setSubject("Testing Notification Service");
messageTemplate.setText("TAAAAADDDDDDDDDd");
getMailSender().send(messageTemplate);
}
/* (non-Javadoc)
* @see com.pmc.ws.notificationservice.NotificationService#notifyByEmail(com.pmc.ws.notificationservice.GenericRequest genericRequest ,)com.pmc.ws.notificationservice.EmailMessage emailMessage ,)java.lang.String messageType ,)java.util.List<com.pmc.ws.notificationservice.PlaceHolder> placeHolder )*
*/
public com.pmc.ws.notificationservice.GenericResponse notifyByEmail(com.pmc.ws.notificationservice.GenericRequest genericRequest,com.pmc.ws.notificationservice.EmailMessage emailMessage,java.lang.String messageType,java.util.List<com.pmc.ws.notificationservice.PlaceHolder> placeHolder) {
LOG.info("Executing operation notifyByEmail");
System.out.println(genericRequest);
System.out.println(emailMessage);
System.out.println(messageType);
System.out.println(placeHolder);
try {
com.pmc.ws.notificationservice.GenericResponse _return = new GenericResponse();
_return.setResponseCode(1);
_return.setResponseMessage("testing");
_return.setResponseStatus("Seding test email");
prepareAndSendEmail();
return _return;
} catch (Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex);
}
}

}



When I deploy it i am getting following exception.
================================

<exception-info>
<nesting-level>1</nesting-level>
<msg-loc-info>
<loc-token />
<loc-message>Error creating bean with name 'org.apache.servicemix.cxfse.CxfSeEndpoint#0' defined in file [C:\apache-servicemix-4.2\data\jbi\Notification-sa\sus\Notification-se-su\xbean.xml]: Cannot create inner bean 'com.pmc.ws.notificationservice.NotificationServiceImpl#0' of type [com.pmc.ws.notificationservice.NotificationServiceImpl] while setting bean property 'pojo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.pmc.ws.notificationservice.NotificationServiceImpl#0' defined in file [C:\apache-servicemix-4.2\data\jbi\Notification-sa\sus\Notification-se-su\xbean.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'mailSender' of bean class [com.pmc.ws.notificationservice.NotificationServiceImpl]: Bean property 'mailSender' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?</loc-message>
<stack-trace><![CDATA[org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.servicemix.cxfse.CxfSeEndpoint#0' defined in file [C:\apache-servicemix-4.2\data\jbi\Notification-sa\sus\Notification-se-su\xbean.xml]: Cannot create inner bean 'com.pmc.ws.notificationservice.NotificationServiceImpl#0' of type [com.pmc.ws.notificationservice.NotificationServiceImpl] while setting bean property 'pojo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.pmc.ws.notificationservice.NotificationServiceImpl#0' defined in file [C:\apache-servicemix-4.2\data\jbi\Notification-sa\sus\Notification-se-su\xbean.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'mailSender' of bean class [com.pmc.ws.notificationservice.NotificationServiceImpl]: Bean property 'mailSender' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:230)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:117)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1245)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at org.apache.servicemix.common.xbean.AbstractXBeanDeployer.deploy(AbstractXBeanDeployer.java:87)
at org.apache.servicemix.common.BaseServiceUnitManager.doDeploy(BaseServiceUnitManager.java:88)
at org.apache.servicemix.common.BaseServiceUnitManager.deploy(BaseServiceUnitManager.java:69)
at org.apache.servicemix.jbi.deployer.artifacts.ServiceUnitImpl.deploy(ServiceUnitImpl.java:104)
at org.apache.servicemix.jbi.deployer.impl.ServiceAssemblyInstaller.deploySUs(ServiceAssemblyInstaller.java:207)
at org.apache.servicemix.jbi.deployer.impl.ServiceAssemblyInstaller.install(ServiceAssemblyInstaller.java:85)
at org.apache.servicemix.jbi.deployer.impl.Deployer.onBundleStarted(Deployer.java:352)
at org.apache.servicemix.jbi.deployer.impl.Deployer.bundleChanged(Deployer.java:282)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:919)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:227)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:149)
at org.eclipse.osgi.framework.internal.core.Framework.publishBundleEventPrivileged(Framework.java:1350)
at org.eclipse.osgi.framework.internal.core.Framework.publishBundleEvent(Framework.java:1301)
at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:362)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:280)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:272)
at org.apache.felix.karaf.shell.osgi.InstallBundle.doExecute(InstallBundle.java:54)
at org.apache.felix.karaf.shell.console.OsgiCommandSupport.execute(OsgiCommandSupport.java:41)
at org.apache.felix.gogo.commands.basic.AbstractCommand.execute(AbstractCommand.java:35)
at org.apache.felix.gogo.runtime.shell.CommandProxy.execute(CommandProxy.java:50)
at org.apache.felix.gogo.runtime.shell.Closure.execute(Closure.java:229)
at org.apache.felix.gogo.runtime.shell.Closure.executeStatement(Closure.java:162)
at org.apache.felix.gogo.runtime.shell.Pipe.run(Pipe.java:101)
at org.apache.felix.gogo.runtime.shell.Closure.execute(Closure.java:79)
at org.apache.felix.gogo.runtime.shell.CommandSessionImpl.execute(CommandSessionImpl.java:71)
at org.apache.felix.karaf.shell.console.jline.Console.run(Console.java:181)
at java.lang.Thread.run(Thread.java:595)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.pmc.ws.notificationservice.NotificationServiceImpl#0' defined in file [C:\apache-servicemix-4.2\data\jbi\Notification-sa\sus\Notification-se-su\xbean.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'mailSender' of bean class [com.pmc.ws.notificationservice.NotificationServiceImpl]: Bean property 'mailSender' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1279)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:219)
... 42 more
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'mailSender' of bean class [com.pmc.ws.notificationservice.NotificationServiceImpl]: Bean property 'mailSender' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:801)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:651)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:78)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:59)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1276)
... 48 more



Any Help will be appreciated.

Thanks & Regards,
Chirag Borkar







 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you sure you deployed the right class ?
 
Chirag Borkar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ya surely.....I have properly bundled it as the Service assembly and
I m using sericemix for deploying it....
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just in case, unbundle it and decompile the class file. (using jad or other decompilers). I can't see anything wrong with your sources.
 
Chirag Borkar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ohh k I got it solved...

In the NotificationServiceImpl Class i have changed the data type to the "mailSender" variable.

Earlier it was : private MailSender mailSender;

Now it is : private JavaMailSender mailSender;

And it started working...However interface JavaMailSender extends MailSender...so it must work...

I have also tried by keeping its data type of the JavaMailSenderImpl still it was showing same error.

But anyways...Thank you very much for all you response.

Appreciated.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

And it started working...However interface JavaMailSender extends MailSender...so it must work...


Yes, I checked that too. The wiring worked on my environment (Spring 3.0.2). Which version of Spring are you using ?

Anyway, it's good that you found a way around this problem !
 
Chirag Borkar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess we are using Spring 3.0.2 but i have observed one thing,

There are 3 jars available in my classpath...

1) spring-context-support-2.5.6.jar
2) spring-context-support-2.5.6.SEC01.jar
3) spring-support-2.0.8.jar

And all of this jar contains the JavaMailSenderImpl.class in it.

Do you think it might cause an issue of this?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Only one of them will be used, I don't think this should cause such a problem. Making a bit of clean up wouldn't hurt though
 
Chirag Borkar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok Cool.

Anyways thanks for your reply.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had the same problem, when you were telling about the changes in the code I came to the following idea (resolution).

My code was correct with the setter for injection. But I had two maven projects, project A and project B.
Project A was de application project and depended on Project B (a service).
When building project A it get the jar from my maven repository instead of building the dependent project B and using that jar, and while changing the code in project B and running in Eclipse went wel, running the same code from the command line would complain about the setter.
After doing mvn install on project B I was able to run the project A from command line successfully.

Hope this helps anyone who also had the same issue when working with multiple projects. (I know I should have made maven modules for these two dependent projects).
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Hi ,

Am getting NotWritablePropertyException.

Configurations:

delivery.xml

<bean id="deliveryResponseService" class="com.telenor.cinclus.metermaid.delivery.impl.DeliveryResponseServiceImpl">
<property name="estimationService" ref="estimationManager"/>
<property name="missingReadingDate" value="${delivery.qualityx.missing.date}" />
<property name="powerDownSeconds" value="10" />
</bean>

Below is the code.

public class DeliveryResponseServiceImpl implements DeliveryResponseService {

/** The logger. */
private Log logger = LogFactory.getLog(getClass());

/** Service for estimating missing values. */
private EstimationService estimationService;

private Date missingReadingDate;

private int powerDownSeconds;


/**
* Sets the estimation service.
*
* @param estimationService
* the new estimation service
*/
public void setEstimationService(final EstimationService estimationService) {
this.estimationService = estimationService;
}


public void setMissingReadingDate(String missingReadingDate) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss.SSS");
try {
this.missingReadingDate = sdf.parse(missingReadingDate);
} catch (ParseException pex) {
String defaultTime = "1900-Jan-01 00:00:00.000";
logger.error("Wrong dateformat: " + missingReadingDate + ". Using default. (" + defaultTime +")");
try { this.missingReadingDate = sdf.parse(defaultTime); }
catch (Exception ex) {}
}
}

public int getPowerDownSeconds() {
return powerDownSeconds;
}

public void setPowerDownSeconds(int powerDownSeconds) {
this.powerDownSeconds = powerDownSeconds;
}
}

Please help on this . I am using Maven to build the project. After generating jars , am checking the class file whether it is getting updated or not, the propety is updated with setter and getter methods.
Still i am not able to find the root cause this Exception. Spring Configuration files are loading in one application and this Class is in other application.

Please help to resolve this exception
 
naveen raavi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
below is the Exception Stack Trace for org.springframework.beans.NotWritablePropertyException.

2013-03-20 10:01:28,421 FATAL [MeterMaidLauncher] [PLAT:config.error] Error creating beans: Error creating bean with name 'deliveryController' defined in class path resource [appContext/delivery.xml]: Cannot resolve reference to bean 'deliveryResponseService' while setting bean property 'responseService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'deliveryResponseService' defined in class path resource [appContext/delivery.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'powerDownSeconds' of bean class [com.telenor.cinclus.metermaid.delivery.impl.DeliveryResponseServiceImpl]: Bean property 'powerDownSeconds' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?. Exiting.
 
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
naveen

I'm going to guess that Spring doesn't like powerDownSeconds having the setter and getter take and return a primitive int. Try Integer instead.
 
naveen raavi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks James for reply, but i tried with Iteger , getting same Exception.
 
James Boswell
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about String? Just like you have done for the date method.
 
Come have lunch with me Arthur. Adventure will follow. This tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic