java.lang.reflect.InvocationTargetException

Spring JIRA | Venkat Ganesh | 4 years ago
  1. 0

    Can I use Spring dependency injection to populate a read only bean for thread safety purpose? After extracting the attached zip file to a folder, I can run the following command successfully and greeted by Pookey. mvn clean compile exec:java ... {noformat} [INFO] --- exec-maven-plugin:1.2.1:java (default-cli) @ spring-readonly --- Hello World! Mar 02, 2013 1:32:00 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from class path resource [application-context.xml] My name is Pookey [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS ... {noformat} My question is simple. I need to comment out setName method implementation in Person.java so that it will be a read only bean. I want spring DI to create this bean using the data values I specify in an xml file and after it is created the thread safe bean will be used by the rest of the application. The intent is the application programmer will create an xml file using the needed data values at run-time, when required and then ask Spring DI to create that bean. Since there are no set methods in the bean, it is thread safe from application point of view. If I comment out the following three lines in Person.java, {code:java} /* public void setName(String name) { this.name = name; } */ {code} and rerun it, I see this error. Is it not true using Java reflection the private data member can also be accessed? Can Spring set a private data member value when the setXXX() method is not available in the source code? Or do we have to revert back to some aspectJ/groovy technique to make this happen? Thanks and regards, Ganesh {noformat} mvn clean compile exec:java ... [INFO] --- exec-maven-plugin:1.2.1:java (default-cli) @ spring-readonly --- Hello World! Mar 02, 2013 1:13:42 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from class path resource [application-context.xml] [WARNING] java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297) at java.lang.Thread.run(Thread.java:722) Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hello' defined in class path resource [application-context.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'name' of bean class [read.only. beans.spring.Person]: Bean property 'name' 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:1427) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1132) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) at read.only.beans.spring.App.main(App.java:18) ... 6 more Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'name' of bean class [read.only.beans.spring.Person]: Bean property 'name' 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:1042) at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:902) at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75) at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:57) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1424) ... 14 more [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 5.881s {noformat}

    Spring JIRA | 4 years ago | Venkat Ganesh
    java.lang.reflect.InvocationTargetException
  2. 0

    Can I use Spring dependency injection to populate a read only bean for thread safety purpose? After extracting the attached zip file to a folder, I can run the following command successfully and greeted by Pookey. mvn clean compile exec:java ... {noformat} [INFO] --- exec-maven-plugin:1.2.1:java (default-cli) @ spring-readonly --- Hello World! Mar 02, 2013 1:32:00 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from class path resource [application-context.xml] My name is Pookey [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS ... {noformat} My question is simple. I need to comment out setName method implementation in Person.java so that it will be a read only bean. I want spring DI to create this bean using the data values I specify in an xml file and after it is created the thread safe bean will be used by the rest of the application. The intent is the application programmer will create an xml file using the needed data values at run-time, when required and then ask Spring DI to create that bean. Since there are no set methods in the bean, it is thread safe from application point of view. If I comment out the following three lines in Person.java, {code:java} /* public void setName(String name) { this.name = name; } */ {code} and rerun it, I see this error. Is it not true using Java reflection the private data member can also be accessed? Can Spring set a private data member value when the setXXX() method is not available in the source code? Or do we have to revert back to some aspectJ/groovy technique to make this happen? Thanks and regards, Ganesh {noformat} mvn clean compile exec:java ... [INFO] --- exec-maven-plugin:1.2.1:java (default-cli) @ spring-readonly --- Hello World! Mar 02, 2013 1:13:42 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from class path resource [application-context.xml] [WARNING] java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297) at java.lang.Thread.run(Thread.java:722) Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hello' defined in class path resource [application-context.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'name' of bean class [read.only. beans.spring.Person]: Bean property 'name' 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:1427) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1132) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) at read.only.beans.spring.App.main(App.java:18) ... 6 more Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'name' of bean class [read.only.beans.spring.Person]: Bean property 'name' 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:1042) at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:902) at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75) at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:57) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1424) ... 14 more [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 5.881s {noformat}

    Spring JIRA | 4 years ago | Venkat Ganesh
    java.lang.reflect.InvocationTargetException
  3. 0

    NullPointerException in init method of EntityManagerFactory

    Stack Overflow | 2 years ago | OanaC
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in file [D:\dev\workspace\StringJPA_2\src\main\resources\applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Re: [jetty-users] Can't configure JNDI global datasource with jetty mave

    eclipse.org | 1 year ago
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException; remaining name 'jdbc/my-db'
  6. 0

    [WG: Sakai QA] Trunk is down

    sakaiproject.org | 1 year ago
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.sakaiproject.entitybroker.impl.entityprovider.EntityProviderAutoRegistrar' defined in file [/home/tomcat-nightly/sakai-demo-oracle/components/entitybroker-pack/WEB-INF/components.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.sakaiproject.sitestats.api.report.ReportDefEntityProvider' defined in class path resource [site-stats-components.xml]: Cannot resolve reference to bean 'org.sakaiproject.sitestats.api.report.ReportManager' while setting bean property 'reportManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.sakaiproject.sitestats.api.report.ReportManager' defined in class path resource [site-stats-components.xml]: Cannot resolve reference to bean 'org.sakaiproject.sitestats.api.StatsManager' while setting bean property 'statsManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.sakaiproject.sitestats.api.StatsManager' defined in class path resource [site-stats-components.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'clusterService' of bean class [org.sakaiproject.sitestats.impl.StatsManagerImpl]: Bean property 'clusterService' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

  1. kjhdofjosvs 3 times, last 1 month ago
  2. Tahir 6 times, last 2 months ago
  3. asdasd 4 times, last 3 months ago
  4. tvrmsmith 4 times, last 3 months ago
  5. dafman 2 times, last 3 months ago
13 more registered users
82 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. org.springframework.beans.NotWritablePropertyException

    Invalid property 'name' of bean class [read.only.beans.spring.Person]: Bean property 'name' 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()
  2. Spring Beans
    AbstractBeanFactory.getBean
    1. org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1042)
    2. org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:902)
    3. org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75)
    4. org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:57)
    5. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1424)
    6. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1132)
    7. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)
    8. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
    9. org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
    10. org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    11. org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    12. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    12 frames
  3. read.only.beans
    App.main
    1. read.only.beans.spring.App.main(App.java:18)
    1 frame
  4. Java RT
    Method.invoke
    1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    4. java.lang.reflect.Method.invoke(Method.java:601)
    4 frames
  5. org.codehaus.mojo
    ExecJavaMojo$1.run
    1. org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
    1 frame
  6. Java RT
    Thread.run
    1. java.lang.Thread.run(Thread.java:722)
    1 frame