Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 9ECED200BBB for ; Thu, 27 Oct 2016 01:57:00 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 9D8D5160AEE; Wed, 26 Oct 2016 23:57:00 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id BE4B8160B04 for ; Thu, 27 Oct 2016 01:56:59 +0200 (CEST) Received: (qmail 82283 invoked by uid 500); 26 Oct 2016 23:56:58 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 82262 invoked by uid 99); 26 Oct 2016 23:56:58 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 26 Oct 2016 23:56:58 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id A104B2C14F9 for ; Wed, 26 Oct 2016 23:56:58 +0000 (UTC) Date: Wed, 26 Oct 2016 23:56:58 +0000 (UTC) From: "Bruno P. Kinoshita (JIRA)" To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (DBCP-471) Cannot use connectionInitSqls property in BasicDataSource MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Wed, 26 Oct 2016 23:57:00 -0000 [ https://issues.apache.org/jira/browse/DBCP-471?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15610090#comment-15610090 ] Bruno P. Kinoshita commented on DBCP-471: ----------------------------------------- Hi, I successfully reproduced the issue with: - Create a simple Maven project - Add the following dependencies: org.apache.commons:commons-dbcp2:2.1.1, and org.springframework:spring-core:3.2.4.RELEASE, and org.springframework:spring-context:3.2.4.RELEASE - Copy the XML with bean definition provided in this issue, as something like spring.xml in the src/main/resources - And then finally create a class with code similar to the following {code} package test; import org.apache.commons.dbcp2.BasicDataSource; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class App { public static void main(String[] args) throws Exception { ApplicationContext ctx = new ClassPathXmlApplicationContext("spring.xml"); BasicDataSource ds = (BasicDataSource) ctx.getBean("dataSource"); System.out.println(ds.getUrl()); ((ClassPathXmlApplicationContext) ctx).close(); System.out.println("OK!"); } } {code} Running this code, instead of getting the DataSource URL, followed by OK!, you will get the following stack trace: {noformat} Oct 27, 2016 12:49:13 PM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@c4437c4: startup date [Thu Oct 27 12:49:13 NZDT 2016]; root of context hierarchy Oct 27, 2016 12:49:13 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from class path resource [spring.xml] Oct 27, 2016 12:49:13 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@49e4cb85: defining beans [dataSource]; root of factory hierarchy Oct 27, 2016 12:49:13 PM org.springframework.beans.factory.support.DefaultListableBeanFactory destroySingletons INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@49e4cb85: defining beans [dataSource]; root of factory hierarchy Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [spring.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'connectionInitSqls' of bean class [org.apache.commons.dbcp2.BasicDataSource]: Bean property 'connectionInitSqls' 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:1423) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1128) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) 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:628) 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 test.App.main(App.java:10) Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'connectionInitSqls' of bean class [org.apache.commons.dbcp2.BasicDataSource]: Bean property 'connectionInitSqls' 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:1420) ... 13 more {noformat} However, I believe this was fixed in [SPR-10995|https://jira.spring.io/browse/SPR-10995], released in Spring 3.2.5.RELEASE. If you update your pom.xml, to use 3.2.5, the issue is gone, and you see the right output. Further issues included in [3.2.5 changelog|http://docs.spring.io/spring/docs/3.2.5.RELEASE/changelog.txt], which was released in 2013-11-06. The issue is not really related to Commons Dbcp, but to dependency injection libraries. And if you use the latest stable versions (4.3.3.RELEASE from 2016-09-20 or 3.2.17.RELEASE from 2016-05-06) you won't have this problem. > Cannot use connectionInitSqls property in BasicDataSource > --------------------------------------------------------- > > Key: DBCP-471 > URL: https://issues.apache.org/jira/browse/DBCP-471 > Project: Commons Dbcp > Issue Type: Bug > Affects Versions: 2.1.1 > Reporter: happybuddha > > Error : > {code}Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'connectionInitSqls' of bean class [org.apache.commons.dbcp2.BasicDataSource]: Bean property 'connectionInitSqls' 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) > {code} > Configuration : > {code} > > > > > > > > Select 1 from dual; > > > > {code} > Similar issue for another bean : https://issues.apache.org/jira/browse/DBCP-469 > The property is listed as a List, has a getter which returns a List but has a setter which takes a Collection > This is also not in line with what was in versions before 2 (dbcp.BasicDataSource) -- This message was sent by Atlassian JIRA (v6.3.4#6332)