Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring injection error with wrong object setters for spring object injection
    primarykey
    data
    text
    <p>This is in relation to this:</p> <p><a href="https://stackoverflow.com/questions/13557861/suddenly-my-spring-xml-wont-instantiate-my-classes-and-error-exception-occurs">Suddenly my spring.xml won&#39;t instantiate my classes and Error Exception occurs</a></p> <p>I changed my spring XML to applicationContext.xml as advice. I did not use the getbeans() to instantiate beans from factory. Instead I used the object injection using the said xml. </p> <p>However I have a problem. There is an error:</p> <pre><code>SEVERE: Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'recordexistuserprofile' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'registeraction' while setting bean property 'registeraction'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'registeraction' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'insertUserProfile' while setting bean property 'insertUserProfile'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'insertUserProfile' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'registeraction' of bean class [lotmovement.business.crud.InsertUserProfile]: Bean property 'registeraction' 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.resolveReference(BeanDefinitionValueResolver.java:275) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104) 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.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4701) at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5204) at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5199) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) at java.util.concurrent.FutureTask.run(FutureTask.java:166) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722) Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'registeraction' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'insertUserProfile' while setting bean property 'insertUserProfile'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'insertUserProfile' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'registeraction' of bean class [lotmovement.business.crud.InsertUserProfile]: Bean property 'registeraction' 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.resolveReference(BeanDefinitionValueResolver.java:275) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104) 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.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269) ... 26 more Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'insertUserProfile' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'registeraction' of bean class [lotmovement.business.crud.InsertUserProfile]: Bean property 'registeraction' 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.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.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269) ... 39 more Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'registeraction' of bean class [lotmovement.business.crud.InsertUserProfile]: Bean property 'registeraction' 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) </code></pre> <p>That is weird since I automatically add the setter through netbeans. There should be no error.</p> <p>Here is my applicationContext.xml.</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"&gt; &lt;bean id="userprofile" class="lotmovement.business.entity.UserProfile"&gt; &lt;/bean&gt; &lt;bean id="entitystart" class="lotmovement.business.crud.EntityStart"&gt; &lt;/bean&gt; &lt;bean id="recordexistuserprofile" class="lotmovement.business.crud.RecordExistUserProfile"&gt; &lt;property name="registeraction" ref="registeraction"/&gt; &lt;property name="entitystart" ref="entitystart"/&gt; &lt;/bean&gt; &lt;bean id="insertUserProfile" class="lotmovement.business.crud.InsertUserProfile"&gt; &lt;property name="registeraction" ref="registeraction"/&gt; &lt;property name="entitystart" ref="entitystart"/&gt; &lt;property name="userprofile" ref="userprofile"/&gt; &lt;/bean&gt; &lt;bean id="registeraction" class="lotmovement.action.RegisterAction"&gt; &lt;property name="insertUserProfile" ref="insertUserProfile"/&gt; &lt;property name="entitystart" ref="entitystart"/&gt; &lt;property name="recordexistuserprofile" ref="recordexistuserprofile"/&gt; &lt;/bean&gt; &lt;/beans&gt; </code></pre> <p>Web.XML</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt; &lt;filter&gt; &lt;filter-name&gt;struts2&lt;/filter-name&gt; &lt;filter-class&gt;org.apache.struts2.dispatcher.FilterDispatcher&lt;/filter-class&gt; &lt;/filter&gt; &lt;filter-mapping&gt; &lt;filter-name&gt;struts2&lt;/filter-name&gt; &lt;url-pattern&gt;/*&lt;/url-pattern&gt; &lt;/filter-mapping&gt; &lt;session-config&gt; &lt;session-timeout&gt; 30 &lt;/session-timeout&gt; &lt;/session-config&gt; &lt;welcome-file-list&gt; &lt;welcome-file&gt;register.jsp&lt;/welcome-file&gt; &lt;/welcome-file-list&gt; &lt;context-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt;/WEB-INF/applicationContext.xml&lt;/param-value&gt; &lt;/context-param&gt; &lt;listener&gt; &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;/web-app&gt; </code></pre> <p>My Classes:</p> <p>RegisterAction</p> <pre><code> /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package lotmovement.action; import com.opensymphony.xwork2.ActionSupport; import lotmovement.business.crud.ApplicationContextProvider; import lotmovement.business.crud.EntityStart; import lotmovement.business.crud.InsertUserProfile; import lotmovement.business.crud.RecordExistUserProfile; import lotmovement.business.entity.UserProfile; import org.apache.commons.lang3.StringUtils; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; public class RegisterAction extends ActionSupport { private static String userId; private static String password; private static String firstName; private static String lastName; private static int securityLevel; EntityStart es; InsertUserProfile iup; RecordExistUserProfile reup; ApplicationContextProvider acp = new ApplicationContextProvider(); ApplicationContext ctx = ApplicationContextProvider.getApplicationContext(); @Override public void validate() { if (reup.checkrecordexist()) { addActionError("record already exist."); } } @Override public String execute() { iup.Insert(); return SUCCESS; } public String getUserId() { return userId; } public void setUserId(String userId) { this.userId = userId; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public int getSecurityLevel() { return securityLevel; } public void setSecurityLevel(int securityLevel) { this.securityLevel = securityLevel; } private String retypepassword; public String getRetypepassword() { return retypepassword; } public void setRetypepassword(String retypepassword) { this.retypepassword = retypepassword; } // * Object setter. public void setEs(EntityStart es) { this.es = es; } public void setIup(InsertUserProfile iup) { this.iup = iup; } public void setReup(RecordExistUserProfile reup) { this.reup = reup; } } </code></pre> <p>ApplicationContextProvider</p> <pre><code>package lotmovement.business.crud; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; public class ApplicationContextProvider implements ApplicationContextAware{ private static ApplicationContext ctx = null; public static ApplicationContext getApplicationContext() { return ctx; } public void setApplicationContext(ApplicationContext ctx) throws BeansException { this.ctx = ctx; } } </code></pre> <p>EntityStart</p> <pre><code>package lotmovement.business.crud; import lotmovement.business.CRUDxxxx.*; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.EntityTransaction; import javax.persistence.Persistence; import lotmovement.business.entity.UserProfile; public class EntityStart { EntityManagerFactory factory; EntityManager em; public void StartDbaseConnection() { factory = Persistence.createEntityManagerFactory("LotMovementPU"); em = factory.createEntityManager(); } public void StartPopulateTransaction(Object entity){ EntityTransaction userTransaction = em.getTransaction(); userTransaction.begin(); em.persist(entity); userTransaction.commit(); em.close(); } public void CloseDbaseConnection(){ factory.close(); } } </code></pre> <p>InsertUserProfile</p> <pre><code>package lotmovement.business.crud; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.EntityTransaction; import javax.persistence.Persistence; import lotmovement.business.entity.UserProfile; import lotmovement.action.LoginAction; import lotmovement.action.RegisterAction; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class InsertUserProfile { ApplicationContextProvider acp = new ApplicationContextProvider(); ApplicationContext ctx = ApplicationContextProvider.getApplicationContext(); UserProfile up; RegisterAction ra; EntityStart es; public void Insert() { up.setUserId(ra.getUserId()); up.setFirstName(ra.getFirstName()); up.setLastName(ra.getLastName()); up.setPassword(ra.getPassword()); up.setSecurityLevel(ra.getSecurityLevel()); es.StartPopulateTransaction(up); es.CloseDbaseConnection(); } public void Update() { } public void Delete() { } public void setUp(UserProfile up) { this.up = up; } public void setRa(RegisterAction ra) { this.ra = ra; } public void setEs(EntityStart es) { this.es = es; } } </code></pre> <p>Checkrecordexist </p> <pre><code>package lotmovement.business.crud; import lotmovement.action.RegisterAction; import lotmovement.business.entity.UserProfile; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class RecordExistUserProfile { RegisterAction ra; EntityStart es; ApplicationContextProvider acp = new ApplicationContextProvider(); ApplicationContext ctx = ApplicationContextProvider.getApplicationContext(); public boolean checkrecordexist() { UserProfile up = es.em.find(UserProfile.class, ra.getUserId()); if (ra.getUserId().equals(up.getUserId())) { return true; } else { return false; } } public void setRa(RegisterAction ra) { this.ra = ra; } public void setEs(EntityStart es) { this.es = es; } } </code></pre> <p>What I did in netbeans was that I just added the spring libraries on my classpath. These are struts 2.3.4, springframework 2.5.6 SEC03 and SpringFramework 3.1.1. I also have check the net but I could not find something witch similarly the same..</p> <p>Thank you very much.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload