Spring框架中mysql資料庫連線池bean設定出錯

iffate發表於2018-07-05

Spring

報錯資訊:(一般屬於bean屬性不同名或者沒有set屬性函式或者set屬性函式命名不規範,導致無法識別初始化bean的內容)
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'studentdao' defined in file [F:\JavaWeb\Spring\src\applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'dataSource' of bean class [com.dongruan.dao.StudentDao]: Bean property 'dataSource' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

例項

<bean id="studentdao" class="com.dongruan.dao.StudentDao">
    <property name="dataSource" ref="dataSource"></property>
</bean>

    /*set函式要規範才會被讀取*/
    public void SetDataSource(DataSource dataSource){
        this.jdbcTemplate=new JdbcTemplate(dataSource);
    }
    /*應該改函式名SetDataSource——>setDataSource,成功執行*

相關文章