java.lang.reflect.InvocationTargetException

Spring JIRA | Venkat Ganesh | 4 years ago
tip
Click on the to mark the solution that helps you, Samebug will learn from it.
As a community member, you’ll be rewarded for you help.
  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 | 2 years 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

    Unable to access context from other threads - Spring Forum

    spring.io | 2 years ago
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lazyBindingProxy.MyReader#sysinit': Scope 'step' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No context holder available for step scope
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