These are chat archives for spring-cloud/spring-cloud

8th
Oct 2015
Dave Syer
@dsyer
Oct 08 2015 05:59
Not sure what you mean. Is that a feature request for the build pack?
Petar Tahchiev
@ptahchiev
Oct 08 2015 10:35

Well as I understand it properties like:

spring.datasource.idleTimeout=30000
spring.datasource.maxLifetime=30000

will be ignored when the java-buildpack is creating a dataSource. And this is exactly what I see in the logs.

Dave Syer
@dsyer
Oct 08 2015 10:44
Yes.
The build pack has no knowledge of Spring Boot. It can't add @ConfigurationProperties to a bean.
Petar Tahchiev
@ptahchiev
Oct 08 2015 12:36

Well, I tried adding my DataSource configuration like this:

    @Bean
    @Profile("cloud")
    public Cloud cloud() {
        return new CloudFactory().getCloud();
    }

    @Bean
    @Profile("cloud")
    @ConfigurationProperties(DataSourceProperties.PREFIX)
    public DataSource dataSource() {
        return cloud().getSingletonServiceConnector(DataSource.class, null);
    }

But now when I deploy I get:

2015-10-08T15:35:20.74+0300 [App/0]      ERR Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
2015-10-08T15:35:20.74+0300 [App/0]      ERR     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
2015-10-08T15:35:20.74+0300 [App/0]      ERR     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
2015-10-08T15:35:20.74+0300 [App/0]      ERR     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
2015-10-08T15:35:20.74+0300 [App/0]      ERR     at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
2015-10-08T15:35:20.74+0300 [App/0]      ERR     at com.mysql.jdbc.Util.handleNewInstance(Util.java:389)
2015-10-08T15:35:20.74+0300 [App/0]      ERR     at com.mysql.jdbc.Util.getInstance(Util.java:372)
2015-10-08T15:35:20.74+0300 [App/0]      ERR     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:958)
2015-10-08T15:35:20.74+0300 [App/0]      ERR     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:937)
2015-10-08T15:35:20.74+0300 [App/0]      ERR     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
2015-10-08T15:35:20.74+0300 [App/0]      ERR     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:872)
2015-10-08T15:35:20.74+0300 [App/0]      ERR     at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2149)
2015-10-08T15:35:20.74+0300 [App/0]      ERR     at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2074)
2015-10-08T15:35:20.74+0300 [App/0]      ERR     at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:794)
2015-10-08T15:35:20.74+0300 [App/0]      ERR     at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)
2015-10-08T15:35:20.74+0300 [App/0]      ERR     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
2015-10-08T15:35:20.74+0300 [App/0]      ERR     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
2015-10-08T15:35:20.74+0300 [App/0]      ERR     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
2015-10-08T15:35:20.74+0300 [App/0]      ERR     at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
2015-10-08T15:35:20.74+0300 [App/0]      ERR     at com.mysql.jdbc.Util.handleNewInstance(Util.java:389)
2015-10-08T15:35:20.74+0300 [App/0]      ERR     at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:399)
2015-10-08T15:35:20.74+0300 [App/0]      ERR     at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:325)
2015-10-08T15:35:20.75+0300 [App/0]      ERR     at org.springframework.jdbc.datasource.SimpleDriverDataSource.getConnectionFromDriver(SimpleDriverDataSource.java:140)
2015-10-08T15:35:20.75+0300 [App/0]      ERR     at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:155)
2015-10-08T15:35:20.75+0300 [App/0]      ERR     at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:120)
2015-10-08T15:35:20.75+0300 [App/0]      ERR     at org.flywaydb.core.internal.util.jdbc.JdbcUtils.openConnection(JdbcUtils.java:50)
2015-10-08T15:35:20.75+0300 [App/0]      ERR     ... 191 more
2015-10-08T15:35:20.75+0300 [App/0]      ERR Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
2015-10-08T15:35:20.75+0300 [App/0]      ERR The last packet sent successfully to the server w
do i need to specify the connection url properties in the application.properties?
Dave Syer
@dsyer
Oct 08 2015 12:42
Yes of course
If you explicitly define your own DataSource
you need to explicitly configure its connections
Petar Tahchiev
@ptahchiev
Oct 08 2015 12:55

ok so the property must be something like this:

spring.datasource.url=${VCAP_SOMETHING:jdbc:mysql://localhost:3306/mydb}

so that it can use the ClearDB service that i have defined

Dave Syer
@dsyer
Oct 08 2015 12:56
I think it says in the blog you linked to
spring.datasource.url: ${cloud.services.mysql.connection.jdbcurl}
Where "mysql" is the service name
Petar Tahchiev
@ptahchiev
Oct 08 2015 13:00
yep.. although I got confused by this: "If you prefer not to write Java code, or don’t want to use Spring Cloud Connectors, you might want to try and use Spring Boot autoconfiguration and external properties (or YAML) files for everything. "
i'll give it a try
Dave Syer
@dsyer
Oct 08 2015 13:00
What's confusing about that?
Petar Tahchiev
@ptahchiev
Oct 08 2015 13:01
well since i'm providing my own DataSource bean, I am actually writing java code ...
Dave Syer
@dsyer
Oct 08 2015 13:04
Yeah. So if you prefer not to do that, it's optional. Only you have to switch off the build pack autoreconfig somehow.
(Which means a couple of lines of Java)
Petar Tahchiev
@ptahchiev
Oct 08 2015 14:05

one more question.. the blog says properties must be like this:

spring.datasource.username: ${cloud.services.mysql.connection.username:sa}

but my env shows this:

System-Provided:
{
 "VCAP_SERVICES": {
  "cleardb": [
   {
    "credentials": {
     "name": "blah",
...

does this mean that my property must be: ${cloud.services.cleardb.credentials.name} ?

Dave Syer
@dsyer
Oct 08 2015 16:26
Yeah, I don't know where "connection" came from
I think that's a typo
Just checking
No, it's "connection"
You can see it in your /env endpoint
Petar Tahchiev
@ptahchiev
Oct 08 2015 16:35
i can't start the server to access the /env actuator
Dave Syer
@dsyer
Oct 08 2015 16:35
You need the database to start up?
Maybe a bad design decision long term
Petar Tahchiev
@ptahchiev
Oct 08 2015 16:36
yeah i'm trying to inject flyway and it fails with exception
Dave Syer
@dsyer
Oct 08 2015 16:36
I'd like to have a failsafe mode where the actuator endpoints come up even if the main app doesn't
That's on the shopping list
Petar Tahchiev
@ptahchiev
Oct 08 2015 16:37
how can i start the actuators even if the main app fails?
Dave Syer
@dsyer
Oct 08 2015 16:46
Well it's hard
Matt Benson
@mbenson
Oct 08 2015 22:39
hi @spencergibb ... I've got a question for you: I want to inspect the FeignClientFactoryBean instances created by the FeignClientsRegistrar, and I want the entity doing so to have another @Bean injected. Can you guide me toward the correct interface that would get me to the right part of the lifecycle?
i.e. after ImportBeanDefinitionRegistrar instances have been called, and with access to the bean definitions and with access the context (I want to install a PropertySource based on the Feign setup)
Matt Benson
@mbenson
Oct 08 2015 22:49
it seems straightforward to implement BeanFactoryPostProcessor and ApplicationContextAware (casting to ConfigurableApplicationContext) but I'm not seeing my dependency @Bean injected
Spencer Gibb
@spencergibb
Oct 08 2015 22:52
@mbenson that is a great question.
Where do you define your bean?
Matt Benson
@mbenson
Oct 08 2015 22:55
in an autoConfiguration
Spencer Gibb
@spencergibb
Oct 08 2015 22:55
with the feign refactoring, each feign client has it’s own application context
Matt Benson
@mbenson
Oct 08 2015 22:56
similar to the ribbon stuff?
Spencer Gibb
@spencergibb
Oct 08 2015 22:56
you probably need to put it in a configuration that is linked via @EnableFeignClients(defaultConfiguration=MyDefaultConfig.class)
Matt Benson
@mbenson
Oct 08 2015 22:58
I see, and the same for my post-processing? Is my hope to inject a @Bean into a BeanFactoryPostProcessor misguided? There would perhaps seem to be a little strangeness to that concept
Spencer Gibb
@spencergibb
Oct 08 2015 22:59
as far as I know a BeanFactoryPostProcessor is a normal bean.
seems like it should work.
Matt Benson
@mbenson
Oct 08 2015 23:00
okay... actually the bean I'm trying to inject represents the main class of the application. If SpringApplication were to expose this property it would simplify things. Any thoughts on how that idea might be received by the core spring-boot team?
(i.e. there is a mutator but not an accessor)
Spencer Gibb
@spencergibb
Oct 08 2015 23:01
No idea. I’m a bit confused about it myself.
Matt Benson
@mbenson
Oct 08 2015 23:02
I'm doing stuff that uses the knowledge of what its main class is. It might not be helpful in the multi-ApplicationContext-per-Feign-client structure anyway. I'll delve into that and see where I land. Thanks.
Spencer Gibb
@spencergibb
Oct 08 2015 23:03
ok
Petar Tahchiev
@ptahchiev
Oct 08 2015 23:55

Hello, I registered searchly elasticsearch on my pws and I get this url for the elasticsearch instance:

          "credentials": {
            "uri": "http://gopivotal:XXXXXXXXXXX@fili-us-east-1.searchly.com",
            "sslUri": "https://gopivotal:XXXXXXXXXXX@fili-us-east-1.searchly.com"
          }

As per the elasticsearch properties I tried adding this property: spring.data.elasticsearch.cluster-nodes=${cloud.services.nemesis-elasticsearch.connection.cluster-nodes:gopivotal:XXXXXX@fili-us-east-1.searchly.com:80} but now i get this exception when i start the server:
icsearch.client.Client]: Factory method 'elasticsearchClient' threw exception; nested exception is java.lang.IllegalStateException: java.lang.NumberFormatException: For input string: "XXXXXXXXXX@fili-us-east-1.searchly.com:80"
2015-10-08T22:41:06.44+0300 [App/0] ERR at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
2015-10-08T22:41:06.44+0300 [App/0] ERR at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
2015-10-08T22:41:06.44+0300 [App/0] ERR at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2015-10-08T22:41:06.44+0300 [App/0] ERR ... 276 more
2015-10-08T22:41:06.44+0300 [App/0] ERR Caused by: java.lang.NumberFormatException: For input string: "XXXXXXXXXX@fili-us-east-1.searchly.com:80"
2015-10-08T22:41:06.44+0300 [App/0] ERR at java.lang.Integer.parseInt(Integer.java:580)
2015-10-08T22:41:06.44+0300 [App/0] ERR at org.springframework.data.elasticsearch.client.TransportClientFactoryBean.afterPropertiesSet(TransportClientFactoryBean.java:85)
2015-10-08T22:41:06.44+0300 [App/0] ERR ... 286 more

I believe it's because the url assumes everything after the colon is port
is this a bug in spring-boot? do we need properties for username and password?