在CF中创建数据源时选择Spring Boot应该使用的参数? [英] Selecting parameters that should be used by Spring Boot when creating datasource in CF?

查看:30
本文介绍了在CF中创建数据源时选择Spring Boot应该使用的参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 Spring Boot (1.3.3.RELEASE)/Cloud (Brixton.M5) 的应用程序,MySQL 部署在 Stackato CF 中,我使用 CrudRepository.不幸的是,当应用程序启动时,Spring Boot 会使用 Stackato 提供的 JDBC url 之一自动配置 DataSource,其中一个包含用户名和密码,例如

I have an app with Spring Boot (1.3.3.RELEASE)/Cloud (Brixton.M5) with MySQL deployed in Stackato CF, where I use CrudRepository. Unfortunately when the app starts, Spring Boot automatically configures DataSource using one of JDBC urls provided by Stackato, one that includes username and password, e.g.

jdbc:mysql://yourUser:yourPassword@172.16.1.48:3306/yourDB

不幸的是,显然 Spring Boot 假设之前的所有内容 : 都是我的主机,而 yourPassword@172.16.1.48:3306 是端口,最后我得到了一个令人讨厌的错误.

Unfortunately apparently then Spring Boot assumes that everything before : is my host, while yourPassword@172.16.1.48:3306 is the port and in the end I get a nasty error.

这是我在应用程序启动时看到的输出:

Here is the output I see when the app starts:

[app.0] 2016-05-27T15:25:59.000Z: 2016-05-27 08:25:59.266 INFO 148 --- [ main] urceCloudServiceBeanFactoryPostProcessor : Auto-reconfiguring beans of type javax.sql.DataSource
[app.0] 2016-05-27T15:25:59.000Z: 2016-05-27 08:25:59.303 INFO 148 --- [ main] o.c.r.o.s.c.s.r.PooledDataSourceCreator : Found Tomcat high-performance connection pool on the classpath. Using it for DataSource connection pooling.
[app.0] 2016-05-27T15:25:59.000Z: 2016-05-27 08:25:59.345 INFO 148 --- [ main] urceCloudServiceBeanFactoryPostProcessor : Reconfigured bean dataSource into singleton service connector org.apache.tomcat.jdbc.pool.DataSource@6a98a805{ConnectionPool[defaultAutoCommit=null; defaultReadOnly=null; defaultTransactionIsolation=-1; defaultCatalog=null; driverClassName=com.mysql.jdbc.Driver; maxActive=4; maxIdle=100; minIdle=0; initialSize=0; maxWait=30000; testOnBorrow=true; testOnReturn=false; timeBetweenEvictionRunsMillis=5000; numTestsPerEvictionRun=0; minEvictableIdleTimeMillis=60000; testWhileIdle=false; testOnConnect=false; password=********; url=jdbc:mysql://uk0pSal2suQS6:pajxAy1Yav22j@172.16.1.48:3306/dd558a39d22d44c059bb438d3b61941ef; username=null; validationQuery=/* ping */ SELECT 1; validationQueryTimeout=-1; validatorClassName=null; validationInterval=30000; accessToUnderlyingConnectionAllowed=true; removeAbandoned=false; removeAbandonedTimeout=60; logAba

这是我后来得到的错误:

and here is he error I get later:

[app.0] 2016-05-27T18:23:19.000Z: 2016-05-27 11:23:19.767 WARN 148 --- [io-44230-exec-6] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: 01S00
[app.0] 2016-05-27T18:23:19.000Z: 2016-05-27 11:23:19.767 ERROR 148 --- [io-44230-exec-6] o.h.engine.jdbc.spi.SqlExceptionHelper : Illegal connection port value 'pajxAy1Yav22j@172.16.1.48:3306'

任何建议如何在不丢弃 CrudTemplate 的情况下解决这个问题?:)

Any suggestions how to go around this without dropping CrudTemplate? :)

我已经尝试在配置文件中使用 spring.datasource.username 和 spring.datasource.password 设置正确的 spring.datasource.url,但似乎 Spring Boot/Cloud 在启动时忽略了这些,而转而使用环境提供的变量.

I already tried setting correct spring.datasource.url with spring.datasource.username and spring.datasource.password in configuration files, but it seems that Spring Boot/Cloud ignores those on startup in favor of variables provided by the environment.

推荐答案

我发现的解决方法是我遵循了 在 Cloud Foundry 中使用 Spring Boot 绑定到数据服务 站点,有效地禁用数据源的自动重新配置,这导致从配置文件中获取连接参数(而不是从 Stackato 环境提供的变量中).

The workaround that I've found is that I've followed the approach described at Binding to Data Services with Spring Boot in Cloud Foundry site, effectively disabling the auto-reconfiguration of the DataSource, which resulted in picking up connection parameters from the configuration file (vs from variables provided by the Stackato environment).

这篇关于在CF中创建数据源时选择Spring Boot应该使用的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆