*
The moose likes Spring and the fly likes org.springframework.beans.NotWritablePropertyException: Invalid property  while sending email Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "org.springframework.beans.NotWritablePropertyException: Invalid property  while sending email" Watch "org.springframework.beans.NotWritablePropertyException: Invalid property  while sending email" New topic
Author

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

Chirag Borkar
Greenhorn

Joined: Mar 01, 2010
Posts: 8
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







Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Are you sure you deployed the right class ?


[My Blog]
All roads lead to JavaRanch
Chirag Borkar
Greenhorn

Joined: Mar 01, 2010
Posts: 8
Ya surely.....I have properly bundled it as the Service assembly and
I m using sericemix for deploying it....
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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

Joined: Mar 01, 2010
Posts: 8
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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

Joined: Mar 01, 2010
Posts: 8
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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

Joined: Mar 01, 2010
Posts: 8
Ok Cool.

Anyways thanks for your reply.
Boechi Loco
Greenhorn

Joined: Apr 19, 2011
Posts: 2
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).
naveen raavi
Greenhorn

Joined: Mar 20, 2013
Posts: 3


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

Joined: Mar 20, 2013
Posts: 3
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.
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1012
    
    5

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

Joined: Mar 20, 2013
Posts: 3
Thanks James for reply, but i tried with Iteger , getting same Exception.
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1012
    
    5

How about String? Just like you have done for the date method.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: org.springframework.beans.NotWritablePropertyException: Invalid property while sending email
 
Similar Threads
org.springframework.beans.factory.BeanCreationException
java.lang.ExceptionInInitializerError
Unable to connect to database
spring bean property is not writable or has an invalid setter method
NotWritablePropertyException,BeanCreationException