Invalid property 'profileManager' of bean class. Bean property 'profileManager' is not writable or has an invalid setter method

StackOverflow https://stackoverflow.com/questions/22303690

  •  12-06-2023
  •  | 
  •  

質問

I've been going through my code and making sure that I didn't miss type anything but I still don't understand what I've done wrong. Below is my code for "ProfileHome" class and "profileManager"

package com.aperturepriorityautoweb.domain;

import java.util.List;

import javax.naming.InitialContext;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Example;

import com.aperturepriorityautoweb.util.HibernateUtil;

/**
 * Home object for domain model class Profile.
 * 
 * @see .Profile
 * @author Hibernate Tools
 */
public class ProfileHome {

    private static final Log log = LogFactory.getLog(ProfileHome.class);

    protected SessionFactory getSessionFactory() {
        try {
            return HibernateUtil.getSessionFactory();
        } catch (Exception e) {
            log.error("Could not locate SessionFactory in JNDI", e);
            throw new IllegalStateException(
                    "Could not locate SessionFactory in JNDI");
        }
    }

    public void persist(Profile transientInstance) {
        log.debug("persisting Profile instance");
        try {
            getSessionFactory().getCurrentSession().persist(transientInstance);
            log.debug("persist successful");
        } catch (RuntimeException re) {
            log.error("persist failed", re);
            throw re;
        }
    }

    public void attachDirty(Profile instance) {
        log.debug("attaching dirty Profile instance");
        try {
            getSessionFactory().getCurrentSession().saveOrUpdate(instance);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }

    public void attachClean(Profile instance) {
        log.debug("attaching clean Profile instance");
        try {
            getSessionFactory().getCurrentSession().lock(instance, LockMode.NONE);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }

    public void delete(Profile persistentInstance) {
        log.debug("deleting Profile instance");
        try {
            getSessionFactory().getCurrentSession().delete(persistentInstance);
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }

    public Profile merge(Profile detachedInstance) {
        log.debug("merging Profile instance");
        try {
            Profile result = (Profile) getSessionFactory().getCurrentSession()
                    .merge(detachedInstance);
            log.debug("merge successful");
            return result;
        } catch (RuntimeException re) {
            log.error("merge failed", re);
            throw re;
        }
    }

    public Profile findById(java.lang.Integer id) {
        log.debug("getting Profile instance with id: " + id);
        try {
            Profile instance = (Profile) getSessionFactory().getCurrentSession()
                    .get("Profile", id);
            if (instance == null) {
                log.debug("get successful, no instance found");
            } else {
                log.debug("get successful, instance found");
            }
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }

    public List findByExample(Profile instance) {
        log.debug("finding Profile instance by example");
        try {
            List results = getSessionFactory().getCurrentSession()
                    .createCriteria(Profile.class).add(Example.create(instance))
                    .list();
            log.debug("find by example successful, result size: "
                    + results.size());
            return results;
        } catch (RuntimeException re) {
            log.error("find by example failed", re);
            throw re;
        }
    }

    /**
     * Returns list of all the profiles for a matching userId.
     */
    @SuppressWarnings("unchecked")
    public List<Profile> getProfiles(int user) {
        List<Profile> profileList = null;
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        try {
            profileList = session
                    .createQuery(
                            "from Profile where user_Id = ? and statusCode <> '"
                                    + Profile.UPLOADED + "'")
                    .setInteger(0, user).list();
            session.getTransaction().commit();
        } catch (HibernateException e) {
            session.getTransaction().rollback();
            throw e;
        }
        return profileList;
    }
}

Below is my controller containing "profileManager"

package com.aperturepriorityautoweb.controllers;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import com.aperturepriorityautoweb.domain.User;
import com.aperturepriorityautoweb.domain.Profile;
import com.aperturepriorityautoweb.domain.ProfileHome;

/**
 * Controller for the Profile List screen.
 */
public class ProfileListController implements Controller {

    public static final String MAP_KEY = "profilesJSPVar";
    public static final String EMP_KEY = "user";

    private ProfileHome profileManager;
    private String successView;

    private static final Logger logger = Logger
            .getLogger(ProfileListController.class);

    /**
     * Returns a list of Profiles database objects in ModelAndView.
     */
    public ModelAndView handleRequest(HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        // Get all profiles not paid for employee with id = 1
        List<Profile> profiles = profileManager.getProfiles(1);
        logger.debug("Showing profiles for user id = " + 1);
        return new ModelAndView(getSuccessView(), MAP_KEY, profiles);
    }

    public ProfileHome getProfileManager() {
        return profileManager;
    }

    public void setProfileManager(ProfileHome profileManager) {
        this.profileManager = profileManager;
    }

    public String getSuccessView() {
        return successView;
    }

    public void setSuccessView(String successView) {
        this.successView = successView;
    }

}

Error I am getting:

2014-03-10 10:24:15,226 ERROR [org.springframework.web.servlet.DispatcherServlet] - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'profileListController' defined in ServletContext resource [/WEB-INF/AperturePriority-servlet.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'profileManager' of bean class [com.aperturepriority.controllers.ProfileListController]: Bean property 'profileManager' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
org.springframework.beans.NotWritablePropertyException: Invalid property 'profileManager' of bean class [com.aperturepriority.controllers.ProfileListController]: Bean property 'profileManager' 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:683)
    at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:584)
    at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:752)
    at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:779)
    at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:768)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:774)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:575)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:405)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:235)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:144)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:614)
    at org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.registerHandler(AbstractUrlHandlerMapping.java:186)
    at org.springframework.web.servlet.handler.SimpleUrlHandlerMapping.initApplicationContext(SimpleUrlHandlerMapping.java:96)
    at org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.java:79)
    at org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:86)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:287)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:825)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:409)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:235)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:144)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:270)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:331)
    at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:155)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:308)
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:252)
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:221)
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:112)
    at javax.servlet.GenericServlet.init(GenericServlet.java:160)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5198)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5481)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)
Mar 10, 2014 10:24:15 AM org.apache.catalina.core.ApplicationContext log
SEVERE: StandardWrapper.Throwable
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'profileListController' defined in ServletContext resource [/WEB-INF/AperturePriority-servlet.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'profileManager' of bean class [com.aperturepriority.controllers.ProfileListController]: Bean property 'profileManager' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
org.springframework.beans.NotWritablePropertyException: Invalid property 'profileManager' of bean class [com.aperturepriority.controllers.ProfileListController]: Bean property 'profileManager' 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:683)
    at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:584)
    at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:752)
    at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:779)
    at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:768)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:774)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:575)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:405)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:235)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:144)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:614)
    at org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.registerHandler(AbstractUrlHandlerMapping.java:186)
    at org.springframework.web.servlet.handler.SimpleUrlHandlerMapping.initApplicationContext(SimpleUrlHandlerMapping.java:96)
    at org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.java:79)
    at org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:86)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:287)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:825)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:409)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:235)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:144)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:270)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:331)
    at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:155)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:308)
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:252)
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:221)
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:112)
    at javax.servlet.GenericServlet.init(GenericServlet.java:160)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5198)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5481)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)

Mar 10, 2014 10:24:15 AM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /AperturePriority threw load() exception
org.springframework.beans.NotWritablePropertyException: Invalid property 'profileManager' of bean class [com.aperturepriority.controllers.ProfileListController]: Bean property 'profileManager' 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:683)
    at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:584)
    at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:752)
    at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:779)
    at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:768)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:774)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:575)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:405)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:235)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:144)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:614)
    at org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.registerHandler(AbstractUrlHandlerMapping.java:186)
    at org.springframework.web.servlet.handler.SimpleUrlHandlerMapping.initApplicationContext(SimpleUrlHandlerMapping.java:96)
    at org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.java:79)
    at org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:86)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:287)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:825)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:409)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:235)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:144)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:270)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:331)
    at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:155)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:308)
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:252)
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:221)
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:112)
    at javax.servlet.GenericServlet.init(GenericServlet.java:160)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5198)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5481)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)

Mar 10, 2014 10:24:15 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Mar 10, 2014 10:24:15 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Mar 10, 2014 10:24:15 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 3241 ms

BEAN XML:

    <?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
         http://www.springframework.org/schema/beans/spring-beans.xsd">

    <!-- URL mapping -->

    <bean id="urlMap"
        class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="urlMap">
            <props>
                <prop key="/profilelist.htm">profileListController</prop>
            </props>
        </property>
    </bean>

    <!-- Controllers -->

    <bean name="profileListController"
        class="com.aperturepriorityautoweb.controllers.ProfileListController">
        <property name="profileManager">
            <ref bean="profileManager" />
        </property>
        <property name="successView">
            <value>profilelist</value>
        </property>
    </bean>

    <!-- Validators -->

    <!-- Model classes -->
    <bean id="userManager" class="com.aperturepriorityautoweb.domain.UserHome" />
    <bean id="profileManager" class="com.aperturepriorityautoweb.domain.ProfileHome" />
    <bean id="sectorManager" class="com.aperturepriorityautoweb.domain.SectorHome" />

    <!-- Utility classes -->


    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass">
            <value>org.springframework.web.servlet.view.JstlView</value>
        </property>
        <property name="prefix">
            <value>/WEB-INF/jsp/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>

    <!-- Spring mail support -->
    <!-- Spring job scheduling -->
    <!-- Spring JMX support -->
    <!-- Resource Bundle -->

</beans>
役に立ちましたか?

解決

sorry I kind of just disappeared for a few days. Sotirios And Mark pretty much pointed me in the right direction. Sotirios wrote:

Can you update your package names? The error doesn't match your class package.

And Mark stated:

I stripped them of all their implementations and removed the spring classes from your bean file, and it loads correctly, are you 100% sure its using the bean file you have here, and not some other copy of it?

To sum up my issue, for some odd reason my project was referencing a BEAN XML of the earlier version of my project. To resolve it I simply closed all other projects I had open (which I should have done to begin with) and changed my projects configuration paths in Eclipse (Java EE - Indigo; probably should have stated what compiler I was using too.) At any rate, this is my first post here on this site and I am quite impressed and thankful for the responses I got. Take it easy guys, hope to be a valuable member here as time goes on and thanks again.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top