[英]Unable to find suitable method for property URL? ComboPooledDataSource, Spring Boot DataSourceBuilder 2.7.0
I am upgrading to spring boot 2.7.0 from 2.3.12.RELEASE as that has vulnerabilities.我正在从 2.3.12.RELEASE 升级到 spring 启动 2.7.0,因为它有漏洞。 My application uses c3p0 for connection pooling and I need to keep using that.我的应用程序使用 c3p0 进行连接池,我需要继续使用它。
Caused by: org.springframework.boot.jdbc.UnsupportedDataSourcePropertyException: Unable to find suitable method for url
at org.springframework.boot.jdbc.UnsupportedDataSourcePropertyException.throwIf(UnsupportedDataSourcePropertyException.java:36) ~[spring-boot-2.7.0.jar:2.7.0]
at org.springframework.boot.jdbc.DataSourceBuilder$ReflectionDataSourceProperties.getMethod(DataSourceBuilder.java:560) ~[spring-boot-2.7.0.jar:2.7.0]
at org.springframework.boot.jdbc.DataSourceBuilder$ReflectionDataSourceProperties.set(DataSourceBuilder.java:542) ~[spring-boot-2.7.0.jar:2.7.0]
at org.springframework.boot.jdbc.DataSourceBuilder.build(DataSourceBuilder.java:181) ~[spring-boot-2.7.0.jar:2.7.0]
at com.informatica.cloud.service.admin.config.PersistenceConfig.dataSource(PersistenceConfig.java:21) ~[main/:?]
at com.informatica.cloud.service.admin.config.PersistenceConfig$$EnhancerBySpringCGLIB$$6bae0fe3.CGLIB$dataSource$0(<generated>) ~[main/:?]
at com.informatica.cloud.service.admin.config.PersistenceConfig$$EnhancerBySpringCGLIB$$6bae0fe3$$FastClassBySpringCGLIB$$4ab5ae17.invoke(<generated>) ~[main/:?]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.3.21.jar:5.3.21]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331) ~[spring-context-5.3.21.jar:5.3.21]
at com.informatica.cloud.service.admin.config.PersistenceConfig$$EnhancerBySpringCGLIB$$6bae0fe3.dataSource(<generated>) ~[main/:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_332]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_332]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_332]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_332]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.21.jar:5.3.21]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.21.jar:5.3.21]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:638) ~[spring-beans-5.3.21.jar:5.3.21]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352) ~[spring-beans-5.3.21.jar:5.3.21]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195) ~[spring-beans-5.3.21.jar:5.3.21]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.21.jar:5.3.21]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.21.jar:5.3.21]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.21.jar:5.3.21]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.21.jar:5.3.21]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.21.jar:5.3.21]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.21.jar:5.3.21]
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.3.21.jar:5.3.21]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1391) ~[spring-beans-5.3.21.jar:5.3.21]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1311) ~[spring-beans-5.3.21.jar:5.3.21]
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:887) ~[spring-beans-5.3.21.jar:5.3.21]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791) ~[spring-beans-5.3.21.jar:5.3.21]
Property: spring.datasource.type=com.mchange.v2.c3p0.ComboPooledDataSource
属性: spring.datasource.type=com.mchange.v2.c3p0.ComboPooledDataSource
The thing that breaks this is the change in DataSourceBuilder in spring boot 2.5.x or higher.打破这一点的是 spring 启动 2.5.x 或更高版本中 DataSourceBuilder 的变化。
DataSourceBuilder:数据源构建器:
private enum DataSourceProperty {
URL(false, "url", "URL"),
DataSourceBuilder will look for setUrl or setURL in the ComboPooledDataSource class and that class has setJdbcUrl method, hence the exception. DataSourceBuilder 将在 ComboPooledDataSource class 中查找 setUrl 或 setURL ,并且 class 具有 setJdbcUrl 方法,因此出现异常。
Any suggestions to not create dataSource bean manually and use auto configuration without breaking the code?有什么建议不要手动创建 dataSource bean 并在不破坏代码的情况下使用自动配置?
Edit: application.properties编辑:application.properties
spring.datasource.url=jdbc:mysql://db-url:3307/service
spring.datasource.username=user
spring.datasource.password=pass
spring.datasource.type=com.mchange.v2.c3p0.ComboPooledDataSource
spring.datasource.pool.driverClass=com.mysql.cj.jdbc.Driver
It's indeed what our documentation states but we used to support C3P0 before.这确实是我们的文档所述,但我们之前曾经支持 C3P0。 I've created https://github.com/spring-projects/spring-boot/issues/31920 to restore the support.我创建了https://github.com/spring-projects/spring-boot/issues/31920来恢复支持。
As per spring boot documentation they support only below database pooling根据 spring 引导文档,它们仅支持低于数据库池
HikariCP光CP
Tomcat pooling Datasource Tomcat 池化数据源
Commons DBCP2公地 DBCP2
Oracle UCP & OracleDataSource Oracle UCP & OracleDataSource
Spring Framework's SimpleDriverDataSource Spring 框架的 SimpleDriverDataSource
H2 JdbcDataSource H2 JdbcDataSource
PostgreSQL PGSimpleDataSource PostgreSQL PGSimpleDataSource
So you need to define the Datasource
manually for C3P0
所以你需要为C3P0
手动定义Datasource
https://docs.spring.io/spring-boot/docs/current/reference/html/data.html#data.sql.datasource.connection-pool https://docs.spring.io/spring-boot/docs/current/reference/html/data.html#data.sql.datasource.connection-pool
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.