Results 1 to 6 of 6

Thread: Help me Please!

  1. #1
    Join Date
    Jun 2006
    Posts
    27

    Red face Help me Please!

    Dear Sir:
    I have a question about the SpringFramework .I tried to many methods but i couldn't solved it.So i ask for you.Thank you very much!
    -----------------------------------------------------------------------
    2006-08-18 03:37:02 StandardContext[/resume]Loading Spring root WebApplicationContext
    2006-08-18 03:37:04 StandardContext[/resume]Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListe ner
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'MyResume' defined in ServletContext resource [/WEB-INF/dataAccessContext-local.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'MyResumeDao' of bean class [data.domain.logic.MyResumeImpl]: Bean property 'MyResumeDao' 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.NotWritablePropertyExcep tion: Invalid property 'MyResumeDao' of bean class [data.domain.logic.MyResumeImpl]: Bean property 'MyResumeDao' 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.setPrope rtyValue(BeanWrapperImpl.java:670)
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:572)
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:737)
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValues(BeanWrapperImpl.java:764)
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValues(BeanWrapperImpl.java:753)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1057)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:857)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:378)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:233)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:145)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:283)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:313)
    at org.springframework.web.context.support.AbstractRe freshableWebApplicationContext.refresh(AbstractRef reshableWebApplicationContext.java:139)
    at org.springframework.web.context.ContextLoader.crea teWebApplicationContext(ContextLoader.java:252)
    at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:190)
    at org.springframework.web.context.ContextLoaderListe ner.contextInitialized(ContextLoaderListener.java: 49)
    at org.apache.catalina.core.StandardContext.listenerS tart(StandardContext.java:3827)
    at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:4343)
    at org.apache.catalina.core.ContainerBase.addChildInt ernal(ContainerBase.java:823)
    at org.apache.catalina.core.ContainerBase.addChild(Co ntainerBase.java:807)
    at org.apache.catalina.core.StandardHost.addChild(Sta ndardHost.java:595)
    at org.apache.catalina.core.StandardHostDeployer.inst all(StandardHostDeployer.java:277)
    at org.apache.catalina.core.StandardHost.install(Stan dardHost.java:832)
    at org.apache.catalina.startup.HostConfig.deployDirec tories(HostConfig.java:701)
    at org.apache.catalina.startup.HostConfig.deployApps( HostConfig.java:432)
    at org.apache.catalina.startup.HostConfig.start(HostC onfig.java:983)
    at org.apache.catalina.startup.HostConfig.lifecycleEv ent(HostConfig.java:349)
    at org.apache.catalina.util.LifecycleSupport.fireLife cycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1091)
    at org.apache.catalina.core.StandardHost.start(Standa rdHost.java:789)
    at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1083)
    at org.apache.catalina.core.StandardEngine.start(Stan dardEngine.java:478)
    at org.apache.catalina.core.StandardService.start(Sta ndardService.java:480)
    at org.apache.catalina.core.StandardServer.start(Stan dardServer.java:2313)
    at org.apache.catalina.startup.Catalina.start(Catalin a.java:556)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.start(Bootst rap.java:287)
    at org.apache.catalina.startup.Bootstrap.main(Bootstr ap.java:425)

    2006-08-18 03:37:04 StandardContext[/resume]Closing Spring root WebApplicationContext

  2. #2
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    667

    Lightbulb What's the relevant property actually called?

    Quote Originally Posted by hanshuang
    Invalid property 'MyResumeDao' of bean class [data.domain.logic.MyResumeImpl]: Bean property 'MyResumeDao' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?
    This is the important part; it means what it says (like most Spring errors, it's pretty helpful). If you could post the source of your MyResumeImpl class, we can help you further. But as a wild guess, I'd say that if you change your XML file to say "myResumeDao" instead, it should work (assuming your property names start with a lowercase letter).

    By the way, please note two items of forum etiquette:
    • Please use the thread title to summarise the problem, instead of just saying "please help". This is true for any forum anywhere.
    • Please wrap your code, stack traces, XML files, etc in [ CODE][ /CODE] tags (without the spaces) so it's more readable. People will then be more inclined to help you.
    HTH,
    Andrew Swan
    "Now is the EJB of our discontent made glorious Spring"

  3. #3
    Join Date
    Jun 2006
    Posts
    27

    Default Below is my XML and class.Check it please.

    applicationContext.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
    <property name="locations">
    <list>
    <value>WEB-INF/jdbc.properties</value>
    </list>
    </property>
    </bean>
    </beans>
    --------------------------------------------------------------------------
    dataAccessContext.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="${jdbc.driverClassName}"/>
    <property name="url" value="${jdbc.url}"/>
    <property name="username" value="${jdbc.username}"/>
    <property name="password" value="${jdbc.password}"/>
    </bean>

    <!-- Transaction manager for a single JDBC DataSource -->
    <!-- (see dataAccessContext-jta.xml for an alternative) -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
    <property name="dataSource" ref="dataSource"/>
    </bean>

    <!-- SqlMap setup for iBATIS Database Layer -->
    <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClient FactoryBean">
    <property name="configLocation" value="WEB-INF/sql-map-config.xml"/>
    <property name="dataSource" ref="dataSource"/>
    </bean>

    <bean id="myresumeDao" class="data.dao.SqlMapMyResumeDao">
    <property name="sqlMapClient" ref="sqlMapClient"/>
    </bean>

    <bean id="MyResume" class="data.domain.logic.MyResumeImpl">
    <property name="MyResumeDao" ref="myresumeDao"/>
    </bean>

    </beans>
    --------------------------------------------------------------------------
    web.xml

    <?xml version="1.0" encoding="ISO-8859-1"?>

    <!DOCTYPE web-app PUBLIC
    "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">

    <web-app>

    <display-name>Resume</display-name>

    <description>Resume application</description>


    <context-param>
    <param-name>webAppRootKey</param-name>
    <param-value>resume.root</param-value>
    </context-param>




    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
    /WEB-INF/dataAccessContext-local.xml /WEB-INF/applicationContext.xml
    </param-value>

    </context-param>




    <listener>
    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    </listener>


    <servlet>
    <servlet-name>resume</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
    <load-on-startup>2</load-on-startup>
    </servlet>

    <servlet-mapping>
    <servlet-name>resume</servlet-name>
    <url-pattern>*.htm</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    </welcome-file-list>
    </web-app>
    ---------------------------------------------------------------------
    MyResume.java

    package data.domain;
    import java.io.Serializable;
    public class MyResume implements Serializable {
    private static final long serialVersionUID = 1L;
    private String name;
    private int age;
    private String sex;
    private String phone;
    private String email;
    private String education;
    private String experience;
    private String effect;
    private String qualification;
    private String hobby;
    public int getAge() {
    return age;
    }
    public void setAge(int age) {
    this.age = age;
    }
    public String getEducation() {
    return education;
    }
    public void setEducation(String education) {
    this.education = education;
    }
    public String getEffect() {
    return effect;
    }
    public void setEffect(String effect) {
    this.effect = effect;
    }
    public String getEmail() {
    return email;
    }
    public void setEmail(String email) {
    this.email = email;
    }
    public String getExperience() {
    return experience;
    }
    public void setExperience(String experience) {
    this.experience = experience;
    }
    public String getHobby() {
    return hobby;
    }
    public void setHobby(String hobby) {
    this.hobby = hobby;
    }
    public String getName() {
    return name;
    }
    public void setName(String name) {
    this.name = name;
    }
    public String getPhone() {
    return phone;
    }
    public void setPhone(String phone) {
    this.phone = phone;
    }
    public String getQualification() {
    return qualification;
    }
    public void setQualification(String qualification) {
    this.qualification = qualification;
    }
    public String getSex() {
    return sex;
    }
    public void setSex(String sex) {
    this.sex = sex;
    }
    }
    --------------------------------------------------------------------------
    MyResumeDao.java

    package data.dao;
    import java.util.List;
    import org.springframework.dao.DataAccessException;
    public interface MyResumeDao {
    public List getMyResumeList() throws DataAccessException;

    }

    --------------------------------------------------------------------------
    MyResumeImpl.java

    package data.domain.logic;
    import java.util.List;
    import data.dao.MyResumeDao;
    public class MyResumeImpl implements MyResumeFacade{
    private MyResumeDao myresumeDao;
    public void setMyResumeDao(MyResumeDao myresumeDao){
    this.myresumeDao = myresumeDao;
    }

    public List getMyResumeList(){
    return this.myresumeDao.getMyResumeList();
    }

    }
    ----------------------------------------------------------------------
    MyResumeFacade.java

    package data.domain.logic;
    import java.util.List;

    public interface MyResumeFacade {
    List getMyResumeList();
    }
    -------------------------------------------------------------------------
    Thanks!

  4. #4
    Join Date
    Jul 2006
    Location
    Philadelphia, PA, USA
    Posts
    341

    Default Change property name

    Hi hanshuang,

    I can't tell from your last post if you took andrew's advice or not:

    Originally Posted by andrews
    But as a wild guess, I'd say that if you change your XML file to say "myResumeDao" instead, it should work (assuming your property names start with a lowercase letter).
    Look at your dataAccessContext.xml:

    Code:
    dataAccessContext.xml
    
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    
      <bean id="myresumeDao" class="data.dao.SqlMapMyResumeDao"> 
        <property name="sqlMapClient" ref="sqlMapClient"/>
      </bean>
    
      <bean id="MyResume" class="data.domain.logic.MyResumeImpl">
        <property name="MyResumeDao" ref="myresumeDao"/>
      </bean>
    
    </beans>
    Notice that the lone property of the "MyResume" bean has a name of "MyResumeDao" instead of "myResumeDao"? If you change the property name in your context file, it should work.

    Hope that helps!

    -Arthur Loder

  5. #5
    Join Date
    Jul 2006
    Location
    Philadelphia, PA, USA
    Posts
    341

    Default Bean naming conventions

    Hi Again Hanshuang,

    In addition, I wanted to point out some things that made it a little more difficult for me (and maybe others) to understand your posted code and config files. Here are a few suggestions:

    1) You have a MyResume class and a MyResumeImpl class. Typically, if you have two Java files someName and someNameImpl, the someName is an interface, and someNameImpl is a concrete class implementing that interface. In your case, the MyResumeImpl class does not implement a MyResume interface, so the naming is misleading. Because MyResumeImpl implements the MyResumeFacade interface, a better name for it might be MyResumeFacadeImpl.

    2) You may have an application-specific reason for the naming, but usually domain objects do not start with a "My" prefix (e.g. MyResume). Sometimes local variables are given names with a "my" prefix (lowercase because it is not a type but a local variable name). For instance:
    Code:
    public class ResumeManager {
      public Resume getResume(String id) {
        Resume myResume = resumeDao.getResume(id);
      }
    }
    But if you do not have a "Resume" domain object and the "My" prefix on MyResume does not add any value, I would remove it. This would mean it would make sense to remove "My" from all of the other classes/interfaces, but that is not too difficult.

    3) You are not consistent in your bean naming:
    Code:
    <bean id="myresumeDao" class="data.dao.SqlMapMyResumeDao">
      <property name="sqlMapClient" ref="sqlMapClient"/>
    </bean>
    
    <bean id="MyResume" class="data.domain.logic.MyResumeImpl">
      <property name="MyResumeDao" ref="myresumeDao"/>
    </bean>
    It is a convention to start bean names with a lowercase letter. So your MyResume bean could be myResume instead. Also, your myresumeDao bean could be re-named myResumeDao so that it is the same name as the interface except with a lowercased first letter. And of course, you should change the MyResumeDao property so that it is lowercased. Following these conventions will help other Spring users more easily understand your code and config files. Of course, there is nothing to stop you from going against conventions, but without a good reason, you might as well follow them (especially when this whole post came about because of misnaming). Note: the MyResume bean should actually be named myResumeFacade, especially if you rename the MyResumeImpl class. You usually name a bean who's class implements an interface the name of the interface. Because MyResumeImpl implements the MyResumeFacade interface, you should name the bean myResumeFacade.

    4) Last suggestion regarding your MyResumeImpl class:
    Code:
    public class MyResumeImpl implements MyResumeFacade {
      private MyResumeDao myresumeDao;
    
      public void setMyResumeDao(MyResumeDao myresumeDao){
        this.myresumeDao = myresumeDao;
      }
    In this case, your property of type MyResumeDao is not named myResumeDao, so it does not have a true JavaBean's style setter method (you use setMyResumeDao instead of setMyresumeDao). Once again, you can name your properties whatever you want. However, it is not even an entirely different name; it is the convention with a slightly different capitalization scheme. Not a big deal, but I would strive to make things as consistent as possible.

    Let me know if you have any questions, and sorry for being so nosey; I think your code would be more understandable if you follow some of the conventions though.

    -Arthur Loder

  6. #6
    Join Date
    Jun 2006
    Posts
    27

    Default Dear Arthur Loder.Thank you very much

    Dear Arthur Loder:
    I'm very happy .Thanks for your help and ardor.I clearly know the name rule and so many experience.I thanks for the spring forum because it answer question is so rapid and so experience.I love it .I love SpringFramework.but i more love the expert.
    HansHuang.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •