Invalid property 'name' of bean class

在Struts2 +  Hibernate4 +  Spring3.2 整合的时候出现的:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: 
        Error creating bean with name 'dataSource' defined in class path resource [applicationContext.xml]: 
        Error setting property values; 
        nested exception is org.springframework.beans.NotWritablePropertyException: 
       Invalid property 'name' of bean class [org.apache.commons.dbcp.BasicDataSource]: 
       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 org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
    at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)
    at com.ssh.test.Test.main(Test.java:25)
Caused by: org.springframework.beans.NotWritablePropertyException: 
       Invalid property 'name' of bean class [org.apache.commons.dbcp.BasicDataSource]: 
      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)
    ... 13 more


我的applicationContext.xml配置文件是这样的:



    
    
    
    
        
        
        
        
        
        
        
        
        
        
    
    
    
        
        
        
        
        
            
                org.hibernate.dialect.MySQLDialect
                update
                true
            
            
        
        
        
            
                com/ssh/domain/Employee.hbm.xml
            
        
    
    
    


原来是:

 name" value="root"/>
写错了,改成:

 username" value="root"/>

问题解决。

你可能感兴趣的:(spring)